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

iOS开发-UISwipeGestureRecognizer滑动手势

时间:2015-06-18 19:10:29      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧:

    UISwipeGestureRecognizer  *upSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
    upSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:upSwipeGestureRecognizer];
    
    
    UISwipeGestureRecognizer  *downSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
    downSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:downSwipeGestureRecognizer];
    
    
    UISwipeGestureRecognizer  *leftSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
    leftSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:leftSwipeGestureRecognizer];
    
    
    UISwipeGestureRecognizer  *rightSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
    rightSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:rightSwipeGestureRecognizer];

手势处理:

-(void)swipeGestureRecognizer:(UISwipeGestureRecognizer *)recongnizer{
    if (recongnizer.direction==UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"向上滑动");
        NSLog(@"博客园-FlyElephant");
    }
    
    if (recongnizer.direction==UISwipeGestureRecognizerDirectionDown) {
        NSLog(@"向下滑动");
        NSLog(@"原文地址:http://www.cnblogs.com/xiaofeixiang");
    }
    
    if (recongnizer.direction==UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"向左滑动");
        NSLog(@"iOS技术交流群:228407086");
    }
    
    if (recongnizer.direction==UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"向右滑动");
    }
}

效果图:

技术分享

iOS开发-UISwipeGestureRecognizer滑动手势

标签:

原文地址:http://www.cnblogs.com/xiaofeixiang/p/4586316.html

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