且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在UIScrollView中滚动而不触发touchesCancelled

更新时间:2023-11-17 23:52:40

我有完全相同的问题(浪费了很多时间)。
然后我尽快设置 cancelsTouchesInView 属性(我在 viewDidLoad )。 ..它为我工作(如下所示

I had exactly the same problem (and wasted a lot of time). Then I tried to set the cancelsTouchesInView property as soon as possible (I did it in viewDidLoad)... and it worked for me (as shown here)!

- (void)viewDidLoad {
    [super viewDidLoad];
    /* other initializations */
    scrollView.panGestureRecognizer.cancelsTouchesInView = NO;
}

这适用于iOS 5.在iOS 5之前,您需要遍历所有识别器,找到panGestureRecognizer,然后设置属性。
所以这应该是一个通用的解决方案:

This works in iOS 5. Before iOS 5 you need to go through all the recognizers, find the panGestureRecognizer, and then set the property. So this should be a universal solution:

- (void)viewDidLoad {
    [super viewDidLoad];
    /* other initializations */
    for (UIGestureRecognizer *gesture in scrollView.gestureRecognizers){
        if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]){
        gesture.cancelsTouchesInView = NO;    
    }
}