UIScrollView contained inside of UICollectionViewCell not passing touch event to the CollectionView cell - ios

I have a UIScrollView inside a UICollectionViewCell so I can zoom an image within that ScrollView.
When I click the image I would like the CollectionViewCell to receive the event and pass it to the UICollectionView delegate.
I tried adding the following UIGestureRecognizerDelegate to the container of the UIScrollView:
-(BOOL)gestureRecognizer:ShouldReceiveTouch:
According to the answer I read the touch event should be passed on to the parent view - in this case the CollectionViewCell, but it isn't happening.
What should I do?
Edit
Please note that I'm not trying to pinch zoom inside the cell but rather be able to receive the touch events of the cell.

Thats a good question as I was having the same problem. The only way I could get the uicollectionviewcell to respond to touches (intercepted from the uiscrollview) was to set
userinteractionenabled = NO
on the scrollview.

Related

Addsubview in touchesBegan, subview must intercept touchesMoved

I have a UICollectionView in my UIViewController. When a touchesBegan is call on one of the UICollectionViewCell I create a UIView added to the UIViewController.view, at the exactly frame of the UICollectionViewCell (A kind of overlay).
That I would like, is instead of the touchesMoved is called in the UICollectionView, it must be called in my new UIView.
To resume, I juste want to make a kind of drag & drop with the view created above the UICollectionViewCell.
To do this, I have tried to disable userinteraction with no success.
Any help or advice would be appreciated.
Thanks

Touches lost on UIScrollview

I am using a UIView subclass which can be resized by dragging on the borders and it is added as subview on a UIScrollView. I am also using a UIGestureRecognizer subclass to move the view on the UIScrollView such that the custom view remains visible and the scrollview autoscrolls.
This setup is working as intended but for one problem. Whenever the custom view is resized, the touches on UIScrollView are lost, i.e the scrollview does not recognise the tap or scroll on it unless the custom view is tapped or dragged once again. I have found that after resizing, neither custom UIView nor custom UIGestureRecognizer's touches began, cancelled or ended are called.
Where might the problem be?

Move subview inside UICollectionViewCell upon touch

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.

Swipe gesture on imageview inside image view collection

I'm trying to add a swipe gesture to an image located in an UICollectionView
This is my existing hierarchy:
I've tried adding the swipe gesture to the UICollectionView as well as the UICollectionViewCell representing the image but neither worked.
In another UIViewController I have a UITableViewCell to which I added the swipe gesture and everything works fine so I'm sure my gesture initialization is correct, I'm adding the gesture to the UICollectionView at the method viewDidLoad, is that the right place or should I place it in different method?

UIScrollView within UICollectionViewCell Not Working

I have a UICollectionView with a custom UICollectionViewCell. The UICollectionView scrolls horizontally, with each cell occupying all of the visible screen.
The UICollectionViewCell has a UIView subview, which in turn has a UIScrollView subview.
The UIScrollView is intended to scroll vertically, but it's not scrolling at all. I've tried setting the scroll view's contentSize with no success.
I suspect that the UIScrollView is not getting any touch events rather than it being a size issue.
Any suggestions?
EDIT >>
I'm now sure it's an event problem rather than anything specific to the UIScrollView.
I've now overridden the pointInside: method in the UIView in the UICollectionViewCell and can see that it now returns false every time I tap on it. In that case you'd think that the tap event would propagate to the next subview , but the UIView still isn't getting events. I've tried adding a UIGestureRecognizer to the UIView but it never registers a tap.
Could there be anything here intercepting the events that I'm not aware of?
I've been trying to solve a similar problem with a scrollview, and your edit about events reminded me of this question (which solved my problem again) How can I use a UIButton in a UICollection supplementary view?
Its possible you need to be using a UICollectionReusableView, not a UICollectionViewCell. Changing the class worked for me because I was using a button (and recently a scrollview) in a header.
However I've not tried for cells themselves. For capturing events from a UICollectionViewCell, maybe the following may help?
Getting button action : UICollectionView Cell
Try to disable userInteractionEnabled for the UIView and enable it for your UIScrollView
I'm not sure if this was your problem, but it was mine - and I'm putting it here in case anyone else comes across this for the same reason. I wanted to put a UIScrollView inside a UICollectionReusableView but by accident I had created my custom class as;
class CustomCellHeader: UICollectionViewCell {
}
instead of;
class CustomCellHeader: UICollectionReusableView {
}
Once I changed that, the UIScrollView within my header cell came to life!
Embed the scrollable content in a ScrollView within the cell.
Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:
class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
}
Now scrolling within the cell should work.

Resources