Scrolling in a UIScrollView without triggering touchesCancelled

后端 未结 2 2517
独厮守ぢ
独厮守ぢ 2021-02-20 18:27

Overview

I\'m working on an iPhone game whose code I inherited from another developer. The gaming grid is a UIScrollView having a contentSize of 1000x1000. The grid co

2条回答
  •  渐次进展
    2021-02-20 19:28

    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;
    }
    

    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;    
        }
    }
    

提交回复
热议问题