Reputation: 1491
I am using a UIPanGestureRecognizer
on a UIView
that is in a UICollectionViewCell
. I am using the translationInView
method to get the translation along the X axis and slide the UIView
left and right. It works fine, but now I cannot scroll up and down in the CollectionView if my finger is on a cell. Is there a way to make the PanGestureRecognizer
pass the vertical scrolling to the UICollectionView
?
I am trying to replicate the sliding seen in Reeder.app for iOS.
Upvotes: 3
Views: 1555
Reputation: 295
Once the UIPanGestureRecognizer
activates in your UIView
touches are no longer forwarded through the responder chain, because of that your UICollectionView
is not receiving the touches anymore.
You can try setting your UIView
as the delegate of your UIPanGestureRecognizer
and place the logic of whether the UIPanGestureRecognizer
should activate. You have to implement the delegate's method in your UIView:
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
For example with the code below you would tell it not to activate if the velocity on the y axis of the view is greater than the velocity of the x axis (therefore sending the touches to the UICollectionView
under it)
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
UIPanGestureRecognizer *recognizer = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint velocity =[recognizer velocityInView:self];
if(abs(velocity.y)>=(abs(velocity.x))){
return NO;
}else return YES;
}
Hope this is helpful.
Upvotes: 9