標籤:
8 9 #import "ViewController.h"10 11 @interface ViewController ()12 13 @property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipGestureRecognizer;14 @property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipGestureRecognizer;15 16 @end17 18 @implementation ViewController19 20 - (void)viewDidLoad {21 [super viewDidLoad];22 // Do any additional setup after loading the view, typically from a nib.23 24 _leftSwipGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];25 _rightSwipGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];26 _leftSwipGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;27 _rightSwipGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;28 29 [self.view addGestureRecognizer:self.leftSwipGestureRecognizer];30 [self.view addGestureRecognizer:self.rightSwipGestureRecognizer];31 }32 33 -(void)handleSwipes:(UISwipeGestureRecognizer *)sender34 {35 if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {36 [UIView animateWithDuration:0.5 animations:^{37 CGRect frame = self.swipLabel.frame;38 self.swipLabel.frame = CGRectMake(frame.origin.x - 100, frame.origin.y, frame.size.width, frame.size.height);39 }];40 }else if(sender.direction == UISwipeGestureRecognizerDirectionRight){41 [UIView animateWithDuration:0.5 animations:^{42 CGRect frame = self.swipLabel.frame;43 self.swipLabel.frame = CGRectMake(frame.origin.x + 100, frame.origin.y, frame.size.width, frame.size.height);44 }];45 }46 }47 48 - (void)didReceiveMemoryWarning {49 [super didReceiveMemoryWarning];50 // Dispose of any resources that can be recreated.51 }52 53 @end
ios左右滑動手勢