How to use Gestures on the iPhone

UIgestures  recognizer is an abstract base class for concrete gesture – recognizer classes.

 A gestures- recognizer object (or, simply, a gesture recognizer) de couples the logic for recognizing a gesture and acting on that recognition.

When one of these objects recognizes a common gesture or in same classes, a change in the gesture, it sends an action message to each designated target object

The concrete sub classes are of the following:

A:   UITapGestureRecognizer
B:   UIRotationGestureRecognizer
C:   UISwpieGestureRecognizer
D:   UIPanGestureRecognizer
E:   UILongpressGestureRecognizer.

-(void) viewDidload

-->//for tapping

UITapGestureRecognizer     *recognizer  =
[[ UITapGestureRecognizer alloc] initWithTarget: self
Action:@ selector (gesture action)];
[ self view addGestureRecognizer: recognizer];
[ recognizer release];

-->//for longPress:

UIlongPressGestureRecognizer    * LongPress  =
[[ UILongPressGestureRecognizer alloc] initWithTarget: self
Action : @ Selector  ( gestureAction)];
[ self view addGestureRecognize  :   long press];
[ long press release];

- ->//for swipe left:

UISwipeGestureRecognizer       * swipe1=
[[UISwipeGestureRecognizer  alloc] initWithTarget : self
Action  : @ Selector   ( gesture Action left];
[Swipe1 setDirection : UISwipeGestureRecognizer. Direction left]
[ img view addGestureRecognizer   :  Swipe1];
[  Swipe1 release];

-->// for SwipeRight:

UISwipeGestureRecognizer          *Swipe r  =
[   UISwipe GestureRecognizer alloc]  initWith target  : self action:@  selector  (gestureActionRight)];
[ Swipe setDirection : UISwipeGesturRecognizerDirectionRight];
[  img view  addGestureRecognizer: swipe];
[  swipe r  release];

-->//for swipe up:

UISwipeGestureRecognizer          *swipe u  =
[[ UI SwipeGestureRecognizer alloc] init withTarget : self
action : @ Selector (gesture Action up)];
[SwipeU setDirection: UISwipeGestureRecognizerDirectionup];
[  imgview  addGestureRecognizer : SwipeU];
[ swipe u release];

-->/ for swipe down:

UISwipeGestureRecognizer         *swipe D=
[[ UISwipeGestureRecognizer alloc]  initWith target:  self
action  :@ Selector   (gesture  ActionDown)];
[ SwipeD   setDirection : UISwipeGestureRecognizerDirectionDown];
[  img view addGestureRecognizer:  swipe];
[   swipeD release];
-(void) gestureAction Left
NSLog (  @   “  view Swiped to Left”);
-( void) gestureActionRight
NSLog  (  @   “  view Swiped to Right”);
-(void) gestureActionup
NSLog (@ “view Swiped to up”);
-(void) gestureActionDowns
NSLog (@ “view Swiped to Down”);


Get Updates on Tech posts, Interview & Certification questions and training schedules