我有一个UIPanGestureRecognizer我添加到一个UIScrollView,当UIPanGestureRecognizer遇到某些情况时我想取消触摸/平移事件从去到UIScrollView,现在我有这样的东西:
-(void)panRecognized:(UIPanGestureRecognizer *)sender {
if(/* some logic */) {
[sender cancelsTouchesInView];
}
}
然而调用[sender cancelsTouchesInView]并不能阻止滚动在我的UIScrollView中发生。
我来自一个大的JavaScript背景,我倾向于期望事件以同样的方式运行,我认为这是我的失败,他们没有。我发现很难理解iOS是如何处理事件的
-(void)panRecognized:(UIPanGestureRecognizer *)sender {
if(/* some logic */ && sender.state == UIGestureRecognizerStateBegan) {
[self.scrollView setUserInteractionEnabled:NO];
}
else if(sender.state == UIGestureRecognizerStateEnded)
{
[self.scrollView setUserInteractionEnabled:YES];
}
}