首页 > 移动平台 > 详细

iOS 手势滑动事件绑定

时间:2015-06-09 06:21:31      阅读:491      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!