Scrolling with two fingers with a UIScrollView

后端 未结 14 614
长发绾君心
长发绾君心 2020-11-29 21:29

I have an app where my main view accepts both touchesBegan and touchesMoved, and therefore takes in single finger touches, and drags. I want to im

14条回答
  •  温柔的废话
    2020-11-29 22:08

    In iOS 3.2+ you can now achieve two-finger scrolling quite easily. Just add a pan gesture recognizer to the scroll view and set its maximumNumberOfTouches to 1. It will claim all single-finger scrolls, but allow 2+ finger scrolls to pass up the chain to the scroll view's built-in pan gesture recognizer (and thus allow normal scrolling behavior).

    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(recognizePan:)];
    panGestureRecognizer.maximumNumberOfTouches = 1;
    [scrollView addGestureRecognizer:panGestureRecognizer];
    [panGestureRecognizer release];
    

提交回复
热议问题