UISwipeGestureRecognizer - 用2个手指和3个手指轻扫 - iOS

时间:2012-01-02 09:44:53

标签: iphone swap uiswipegesturerecognizer

如何在同一个View-iOS上检测UISwipeGestureRecognizer 2手指滑动或3个手指滑动

任何人都有想法?

2 个答案:

答案 0 :(得分:4)

我已经为2和3手指滑动创建了一个手势。

       func addTwoFingerSwipeGesture() {
            let gesture = UISwipeGestureRecognizer(target: self, action: "handleTwoFingerSwipe")
            gesture.direction = .Left
            gesture.numberOfTouchesRequired = 2 // 2 finger swipe
            self.view.addGestureRecognizer(gesture)
        }

       func addThreeFingerSwipeGesture() {
            let gesture = UISwipeGestureRecognizer(target: self, action: "handleThreeFingerSwipe")
            gesture.direction = .Left
            gesture.numberOfTouchesRequired = 3 // 3 finger swipe
            self.view.addGestureRecognizer(gesture)
        }


    // Handle Swipe
        func handleTwoFingerSwipe() {
            print("2 finger swipe recognized")
        }

        func handleThreeFingerSwipe() {
            print("3 finger swipe recognized")
        }

答案 1 :(得分:2)

这里“setMinimumNumberOfTouches”取决于你的手指(例如:2/3/4/5)。尝试一次..这可能有助于你

  UIPanGestureRecognizer *pan;
 pan = [[UIPanGestureRecognizer alloc] initWithTarget:self     action:@selector(Swipe4ScrollViews:)];
[pan setMinimumNumberOfTouches:2];
 [_scroll1 addGestureRecognizer:pan];
  [pan release];