Home  >  Blog  >   iPhone  > 

How to use Gestures on the iPhone

Rating: 4
  
 
2394

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

 Gestures- recognizer object (or, simply, a gesture recognizer) decouples the logic for recognizing a gesture and acting on that recognition.

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

Inclined to build a profession as IOS Developer? Then here is the blog post on iPhone Development Certification Training.

How to use Gestures on the iPhone

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”);
}

 

Frequently Asked iPhone Interview Questions & Answers

 

Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
IOS Development TrainingDec 10 to Dec 25
IOS Development TrainingDec 13 to Dec 28
IOS Development TrainingDec 17 to Jan 01
IOS Development TrainingDec 20 to Jan 04
Last updated: 06 December 2022
About Author
Ruchitha Geebu

I am Ruchitha, working as a content writer for MindMajix technologies. My writings focus on the latest technical software, tutorials, and innovations. I am also into research about AI and Neuromarketing. I am a media post-graduate from BCU – Birmingham, UK. Before, my writings focused on business articles on digital marketing and social media. You can connect with me on LinkedIn.

Recommended Courses

1 /15