Addsubview in touchesBegan, subview must intercept touchesMoved - ios

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

Related

How can a UIView subclass get notified when it has been scrolled by its Superview UIScrollView

I am trying to subclass UIView and to get notified when its superviews got scrolled. I tried with UIScrollView DidScroll delegate, But I want to create a standalone UIView to handle its movement on screen by itself. I tried by iterating its superviews and adding KVO for each superviews, but it might lead to performance issues. Can you please suggest some better solution for this?
You can create a protocol for delegation, that you can set in parent UIViewController and implement function in sub view class. and call these protocol function from UIScrollView delegate method.
This should solve your problem

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.

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

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.

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.

Make UICollectionView zoomable?

Is there any method make the UICollectionView zoomable, i.e. when you pinch, all the cells can be zoomed in and out.
I can implement this in UIScrollView by returning the only subview of the UIScrollView from delegate method
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
Since UICollectionView is kind of UIScrollView, is there a way or work around to implement this? Does the UICollectionView has one direct subview that contains all cells?
Thanks
I think what you're asking for looks like what is done in the WWDC1012 video entitled Advanced Collection Views and Building Custom Layouts (demo starts at 20:20).
You basically have to add pinchGesture to you UICollectionView, then pass the pinch properties (scale, center) to the UICollectionViewLayout (which is a subclass of UICollectionViewFlowLayout), your layout will then perform the transformations needed to zoom on the desired cell.

Resources