UIGestureRecognizer class recognizes a sequence of touches & performs on basis of the recognizer. Here is the list of different gesture events.

It’s more useful for adding action events for controls which don’t contain default actions like UIButton.

UITapGestureRecognizer :

Its used for handle single or multiple taps.

UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapped:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void) gestureTapped:(UITapGestureRecognizer)sender {

}

UIPinchGestureRecognizer :

Its used for handle two taps simultaneously. This gesture used generally for image scaling & zooming feature.

UIPinchGestureRecognizer * gest = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(gestureTapped:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void)gestureTapped:(UIPinchGestureRecognizer*)sender {

sender.view.transform = CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale);

sender.scale = 1;

}

Read more: How to Create and Setup a Prefix Header File for iOS

UIRotationGestureRecognizer :

Its used for handle rotation feature. When a user moves two fingers opposite each other circular way. It will rotate the view in the corresponding direction.

UIRotationGestureRecognizer * gest = [[ UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];

gest.delegate = self;

[view addGestureRecognizer:gest];

-(void)rotateImage:(UIRotationGestureRecognizer*)sender {

if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged) {

[sender view].transform = CGAffineTransformRotate([[sender view] transform], [sender rotation]);

[sender setRotation:0];

}

}

UISwipeGestureRecognizer :

Its used for handle actions on swipe. Move views on swiped direction or actions on image with swipe to remove or swipe to load new image.

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwap:)];

switch (self.direction) {

case DirectionFromTop:

swipe.direction = UISwipeGestureRecognizerDirectionDown;

break;

case DirectionFromLeft:

swipe.direction = UISwipeGestureRecognizerDirectionRight;

break;

case DirectionFromBottom:

swipe.direction = UISwipeGestureRecognizerDirectionUp;

break;

case DirectionFromRight:

swipe.direction = UISwipeGestureRecognizerDirectionLeft;

break;

}

[view addGestureRecognizer:swipe];

-(void)didSwap:(UISwipeGestureRecognizer*)gesture {

}

UIPanGestureRecognizer :

Its used for handle dragging actions like moving images into view or moving any other objects on finger movement.

UIPanGestureRecognizer *gest = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanImage:)];

[imgViewStyleOutfit addGestureRecognizer:gest];

– (void)handlePanImage:(UIPanGestureRecognizer *)sender {

static CGPoint originalCenter;

if (sender.state == UIGestureRecognizerStateBegan) {

originalCenter = sender.view.center;

[sender.view.superview bringSubviewToFront:sender.view];

} else if (sender.state == UIGestureRecognizerStateChanged) {

CGPoint translation = [sender translationInView:self.view];

sender.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);

}

}

UILongPressGestureRecognizer :

Its used for handle long press events. For that user needs to press for minimum amount of time to call actions.

UILongPressGestureRecognizer *gest = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hangleLongPress:)];

[view addGestureRecognizer:gest];

-(void)hangleLongPress:(UILongPressGestureRecognizer*)sender {

if (sender.state == UIGestureRecognizerStateBegan) {

}

}

Share
Share