[英]Detecting UIGestureStateEnded in default UIScrollView pan gesture recognizer
[英]Add functionality to standard Pan Gesture Recognizer in a UIScrollView
我试图跟踪手指在UIScrollView
。 我已经将UIScrollView
子类化(见下文),但遗憾的是我添加的手势识别器正在覆盖标准的手势识别器。
结果我得到NSLog(@"Pan")
工作但不幸的是视图不再滚动。
如何让两个手势识别器同时工作?
谢谢。
- (void)viewDidLoad:(BOOL)animated
{
[super viewDidLoad:animated];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[scrollView addGestureRecognizer:panRecognizer];
}
- (void)pan:(id)sender {
NSLog(@"Pan");
}
如果你不想覆盖标准的那个,你只需要同时识别它们。
- (void)viewDidLoad:(BOOL)animated
{
[super viewDidLoad:animated];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
panRecognizer.delegate = self;
[scrollView addGestureRecognizer:panRecognizer];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return TRUE;
}
- (void)pan:(id)sender {
NSLog(@"Pan");
}
编辑 :这种方法有效! 您只需要尽快设置canCancelContentTouches
(我在viewDidLoad
)。
原始答案 :我尝试了一种新的方法,但不幸的是它没有完全发挥作用。
我没有添加手势识别器,而是touchesBegan
UIScrollView
并编写自己的touchesBegan
, touchesMoved
等方法。
这样我知道用户在哪里触摸但不幸的是,每当我将canCancelContentTouches
设置为NO后,每次开始滚动时touchesCancelled
都会触发touchesCancelled
。
有人知道为什么吗? 我也发现了这个 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.