码迷,mamicode.com
首页 > 移动开发 > 详细

ios左右滑动手势

时间:2015-03-05 14:35:14      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

 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

 

ios左右滑动手势

标签:

原文地址:http://www.cnblogs.com/wuyr/p/4315686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!