Move subview inside UICollectionViewCell upon touch - ios

I have a issue in moving the frames inside UICollectionViewCell.
I have a small dot(made up of UIView) present inside the UICollectionViewCell and I have set the UIPanGestureRecognizer on my UICollectionView. Upon panning if the dot is being touched and moved, I want to move the dot inside the cell. I am able to change the frame of dot correctly(as shown by debugger), but the same is not getting reflected on the device screen. Please can someone suggest me what could possibly be wrong. I expect that somehow I have to refresh the views so that same can be reflected on device screen.
Some points if necessary:
1) I have subclassed UICollectionViewFlowLayout and using my own layout.
2) I have kept the UIPanGestureRecognizer on the entire UICollectionView and not in each UICollectionViewCell. I do not want to keep the UIPanGestureRecognizer in each cell. So please do not suggest me that.
edit: 3) The project is not using autolayout.
Yes, I have tried searching on this, but I am unable to find any suitable solution.

Related

Pull to refresh for simple UIView

Can anybody advice how to implement pull to refresh functionality on iOS for a simple UIView without UIScrollView?
I've tried to use UIRefreshControll, but it should be added either to UITableView or UIScrollView, but I have just a UIView. When I add UIRefreshControll to UIView my App is crashing.
I do not want to add UIScrollView to the existing layout, because my screen is splitted to two section: top part is UIView and bottom part is UITableView. If I add UIScrollView to the top part I'll have 2 UIScrollView on the same screen, what I think is not good. But I need pull to refresh for the whole screen, to that user can refresh both top and bottom part of the screen.
I'd appreciate any ideas.
My code example:
public override ViewDidLoad()
{
var refresh = new UIRefreshControl();
MyView.Add(refresh); // crash here
//MyView.AddSubview(refresh); // such option also causes crash
}
It can be done in 2 ways :-
(1.) You need to add pan gesture recogniser interactively to UIView and needs to adjust y position of both UIView and UITableview according to pan movement downwards and after some threshold value you have to move UIView and UITableView back to its default position.
NOTE:- In this case, you have to add circular loader animation also, same as how it comes in UIRefreshControl. This will also be a part of interactive pan gesture.
(2.) You can add UIView as a section header of UITableView.

Selectable UITableViewCells inside of a UIScrollView

I've been trying to programmatically create a UITableView inside of a UIScrollView and I'm having some trouble. Basically I want to have the cells to register as "checked" when they are tapped on. I don't need the UITableView itself to scroll because the UIScrollView will be large enough that this isn't necessary, but I still need the UIScrollView to be able to scroll when the user drags over the UITableView. I'm just overall confused about how gesture recognition works with regard to this project. I can't get the didSelectRowAtIndexPath method to be called, although I can get the didHighlightRowAt method to work. I saw a suggestion to add a UIScrollView onto each cell, but this didn't seem to help. Any guidance is appreciated as I'm unsure how exactly to go about this.
Thanks!
Sounds to me like you should be using custom UIButtons rather than UITableViewCells to allow for selectable content within your UIScrollView.

Adding subview to UICollectionView - disables scrolling

I want to add a subview to a UICollectionView in order to make a left panel that scrolls with the collectionview.
Using
[self.collectionView addSubview:myView]
all touches become disabled and I can no longer scroll the view. I've read that adding a subview to a collectionView like this is bad practice.. is this true? Why does it disable touches from reaching the collectionView event when
userInteractionEnabled = NO
I'm trying to do this: imgur link by grabbing the frame position of the first cell in each section, and adding a dot with to myView with the same y value.
Thanks for any help!
Adding subviews using the addSubview: method to a UICollectionView is very bad practice. It can cause a lot of different problems in the normal behaviour of the CollectionView. It can obstruct the views underneath it, capture the touch events, preventing them from reaching the actual scrollView inside the CollectionView, etc. The subviews added using this method will also not scroll as the other elements in the CollectionView do.
The correct way to do what you want is to implement a new type of UICollectionViewCell for the dots, and compute their locations in the prepareForLayout and layoutAttributesForElementsInRect: methods. Basically you'll have either one or two cells in each row. Which ones will have two rows will be determined by you in the methods I've mentioned.
In fact, Apple's docs have a perfect example that's even more complex than what you're trying you achieve. You should check it out from this link.
May I know the purpose of that scroll view ? Because, if you're looking for a subview that displays only a label or image etc., You can use custom collectionview cell instead if I am not wrong... Hope it helps :) :)

Collection view Cell Animations

I am trying to animate UICollectionviewCells as they are created. I wanted to give each collectionviewcell a frame whose origin would be outside the phone and then I try to animate them, the way I wanted to do this was to use animate with duration and save their actual frames so that I can have the collectionviewCells animate to the so called "actual frames", the problem now is that, so I make one collectionViewcell in one section, so every collectionviewcell has "0" as its origin for the "actual frame", I won't be able to get the correct frames on the screen to animate a uicollectionview cell too. Would anyone have any suggestion for me to achieve the animation?
You may want to check this link: http://www.objc.io/issue-12/collectionview-animations.html.
The standardized idea is to subclass UICollectionViewLayout and then implement the method initialLayoutAttributesForAppearingItemAtIndexPath: to provide the initial positioning properties of the cells.
P.S. Other animations (when you remove a cell or when you rotate your device) are also talked about in the post. Read them if you are interested.

Drawing in screen with finger in UITableView

I am following this excellent small tutorial about drawing on screen in the layer of a UIView (subclass).
http://spritebandits.wordpress.com/
It just works.
There is just one thing. I placed this view as subview of a UITableViewCell which, naturally, is displayed as part of a UITableView.
I guess I would have the same issue when I would place it within an UIScrollView. (UITableView inherits from UIScrollView anyway)
Touches are triggered by my painting view as long as their related movement is horizontal. As soon as I move the finger kinda vertical, even partly, then the UITableView takes over and scrolls the table.
Is there any proper way of stopping the Table to taike control of the touches while the touch is actually within my view?
If it is of importance: I am using storyboard. The cell is a prototype cell with its own subclass of UITableViewCell.
I've implemented this using the same class "Canvas" you're saying and also inside a UITableViewCell. But I didn't use the entire cell for drawing, only a UIView inside of the UITableView as a subview.
I reached the whole user experience by activating and deactivating the UITableView scrolling when that UIView (subview of the cell where I allow the drawing) fires touchesBegan or touchesEnded. So when they touch/move inside the UIView, they're drawing. When it's outside, they're scrolling. So they can't scroll on the UIView because they will be drawing.
The problem in your case is that since the whole cell is the view for drawing, the user cannot scroll in this concrete cell because it's the drawing one.
Hope this will help.
I dont have an answer for that. But there is essentially a work around.
You could get the user in to a drawing mode, where the scrolling for a UItableviewcell is disabled and then
once the user is done with drawing, you could enable scrolling again.
Inclusion of a button anywhere on the screen would help you switch modes.

Resources