2

How do i put a swipe gesture in the new iPhone SDK? I'm trying to detect a swipe gesture over a UIImageView? A swipe up and a swipe down?

Justin Tanner
  • 14,062
  • 17
  • 82
  • 103
NextRev
  • 1,711
  • 4
  • 22
  • 31

4 Answers4

6

There is a new API for this: Refer to this post here.

Community
  • 1
  • 1
P i
  • 29,020
  • 36
  • 159
  • 267
4

There are easier ways to handle gestures in iOS 4.0 see:

http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

Justin Tanner
  • 14,062
  • 17
  • 82
  • 103
2

please download the swipe gesture code from this link:

https://github.com/brow/leaves/downloads

UISwipeGestureRecognizer *settingbtnpress =
[[UISwipeGestureRecognizer alloc]
 initWithTarget:self
 action:@selector(MethodName)];
settingbtnpress.delegate=self;
settingbtnpress.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:settingbtnpress];
[settingbtnpress release];
Jaspreet Singh
  • 1,180
  • 2
  • 12
  • 30
1

Basically you need to override onTouchesBegan and onTouchesEnded. When it begins, record the first position, then at the end compare the last touch to the first touch to see if it is lower or higher.

Matt Williamson
  • 39,165
  • 10
  • 64
  • 72
  • 7
    This really is _not_ the way to do it. Since he's using iOS4 he can use the new `UIGestureRecognizer` which were made for this purpose. Ohmu's answer is better suited. – ynnckcmprnl Sep 28 '10 at 09:19