UIScrollView prevents touchesBegan, touchesMoved, touchesEnded on view controller

前端 未结 5 1929
一整个雨季
一整个雨季 2020-12-05 07:19

I am handling touches for a couple of my UI components in my view controller (custom subclass of UIViewController). It has methods touchesBegan:withEvent:,

5条回答
  •  悲哀的现实
    2020-12-05 08:01

    user1085093's answer worked for me. Once you move the touch more than a small amount, however, it then gets interpreted as a Pan Gesture.

    I overcame this by altering the behaviour of the Pan Gesture recogniser so it requires two fingers:

    -(void)awakeFromNib
    {
        NSArray                 *gestureRecognizers = self.gestureRecognizers;
        UIGestureRecognizer     *gestureRecognizer;
    
        for (gestureRecognizer in gestureRecognizers) {
            if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
                UIPanGestureRecognizer      *pgRecognizer = (UIPanGestureRecognizer*)gestureRecognizer;
                pgRecognizer.minimumNumberOfTouches = 2;
            }
        }
    
    }
    

提交回复
热议问题