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

iOS 手势滑动事件绑定

时间:2015-06-09 06:23:33      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

UIGestureRecognizer 手势响应基类
- UITapGestureRecognizer //点击手势识别器,可以是点击一次,或多次都能识别
- UIPinchGestureRecognizer //捏合手势识别器,用于视图的放大缩小
- UIRotationGestureRecognizer //旋转手势识别器
- UISwipeGestureRecognizer //滑动手势识别器,向上、下、左、右滑动
- UIPanGestureRecognizer //拖动手势识别器
- UILongPressGestureRecognizer //长按手势识别器,常见的有长按跳出一个界面用以编辑


这里演示的是

UISwipeGestureRecognizer  // 上下左右的滑动

ps: 参数详解:self设置代理类,@selector设置事件响应,

然后要设置响应的是哪个view的手势

这里设置的是

self.gameView

/*
 * 绑定手势事件,上下左右
 **/
- (void)bindAction {
    UISwipeGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [self.gameView addGestureRecognizer:recognizer];
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [self.gameView addGestureRecognizer:recognizer];
   
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeTop)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [self.gameView addGestureRecognizer:recognizer];
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeBottom)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.gameView addGestureRecognizer:recognizer];
}




iOS 手势滑动事件绑定

标签:

原文地址:http://my.oschina.net/littleDog/blog/464442

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