2

I want the scroll view just scrolls vertically and I also try to capture horizontal swipes on the scroll view.

I try to subclass UIScrollView and override some method about touch event, but all failed.

The problem seems to be that when a user swipes horizontally with some accidental vertical movement(even just a little), the UIScrollView scrolls and my touchesEnded delegate method never gets called.

world000
  • 1,267
  • 1
  • 8
  • 13

1 Answers1

3

Instead of overriding touchesBegan:withEvent: and other methods, use a UISwipeGestureRecognizer. It's much simpler.

“Gesture Recognizers” in the Event Handling Guide for iOS
UISwipeGestureRecognizer Class Reference

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Thank you for your answer! But the problem still exists. The gesture selector method do NOT get called when a user swipes horizontally with some accidental vertical movement(even just a little). – world000 Feb 06 '12 at 05:08
  • What version of iOS are you targetting? – rob mayoff Feb 06 '12 at 05:46
  • iOS 4.0. BTW, the gesture selector method gets called just when a user swipes and do NOT trigger the vertical movement. – world000 Feb 06 '12 at 06:02
  • 1
    Dig through the scroll view's gesture recognizers to find its pan gesture recognizer and do `[panGestureRecognizer requireGestureRecognizerToFail:self.swipeGestureRecognizer]`. Code to find the pan gesture recognizer here: http://stackoverflow.com/a/3173290/77567 – rob mayoff Feb 06 '12 at 06:11