Monday, 28 September 2015

How to work Gesture Recognization in Ios/Iphone

==> Here See Some Gesture like long Gsture , pin Gesture tap Gesture:
=> Used And Import Gesture Like  ;-UIGestureRecognizerDelegate

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIView *viewSender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    UIRotationGestureRecognizer *aRotationGesture = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotateView:)];
    aRotationGesture.delegate =self;
    [_viewSender addGestureRecognizer:aRotationGesture];
   
==> Used Here PinchGestureRecognization:

    UIPinchGestureRecognizer *aPinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self  action:@selector(pinchView:)];
    aPinch.delegate =self;
    [_viewSender addGestureRecognizer:aPinch];   
 
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)rotateView:(UIRotationGestureRecognizer*)sender{
    _viewSender.transform = CGAffineTransformRotate(_viewSender.transform, sender.rotation);
    [sender setRotation:0];
}

-(void)pinchView:(UIPinchGestureRecognizer*)sender{
    _viewSender.transform = CGAffineTransformScale(_viewSender.transform, sender.scale, sender.scale);
    [sender setScale:1];
}
==> Here Use Gesture Delegate Of Pinchand Recognization Of Gesture Used:

#pragma mark - Delegates
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    return YES;
}
==> Used Some Gesture Using Swipe Gesture Recoganization:-

- (IBAction)swipeHandler:(UISwipeGestureRecognizer*)sender {
   
    switch (sender.direction) {
        case UISwipeGestureRecognizerDirectionDown:
        {   NSLog(@"DOWN");
            break;
        }
        case UISwipeGestureRecognizerDirectionRight:
            NSLog(@"RGHT");
            break;
        default:
            break;
    }
}
@end