ios左右滑动手势

 8 
 9 #import "ViewController.h"
10 
11 @interface ViewController ()
12 
13 @property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipGestureRecognizer;
14 @property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipGestureRecognizer;
15 
16 @end
17 
18 @implementation ViewController
19 
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 *)sender
34 {
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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。