-(void)panRecognized:(UIPanGestureRecognizer *)sender {
if(/* some logic */ && sender.state == UIGestureRecognizerStateBegan) {
[self.scrollView setUserInteractionEnabled:NO];
}
else if(sender.state == UIGestureRecognizerStateEnded)
{
[self.scrollView setUserInteractionEnabled:YES];
}
}
How can I cancel other events when my UIPanGestureRecognizer occurs along side a UIScrollView?
-
31-05-2022 - |
Question
I have a UIPanGestureRecognizer that I added to a UIScrollView, and when certain circumstances with the UIPanGestureRecognizer are met I want to cancel the touch/pan events from going to the UIScrollView, right now I have something like this:
-(void)panRecognized:(UIPanGestureRecognizer *)sender {
if(/* some logic */) {
[sender cancelsTouchesInView];
}
}
however calling [sender cancelsTouchesInView] does not stop scrolling from occurring in my UIScrollView.
I come from a big JavaScript background and I tend to expect events to behave in the same way and I think it's my downfall that they don't. I'm finding it really difficult to understand how events are handled in iOS.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow