码迷,mamicode.com
首页 > 其他好文 > 详细

触摸事件和手势

时间:2014-10-19 16:58:31      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   strong   sp   div   

一、UIView自带有的触摸事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    if (touch.tapCount == 2) // 双击
            NSLog(@"++++++++++++++++++++++++++++++++++++++++%lu", [touch tapCount]);
    if (event.allTouches.count == 2) // 两根手机触摸
            NSLog(@"++++++++++++++++++++++++++++++++++++++++%lu", [event.allTouches count]);
}

只需实现该事件函数即可。但是,注意,若是在UIViewController里有一个UITableView,点击该UITableView,触摸事件是会被UITableView截断的

参考链接:http://www.cnblogs.com/syxchina/archive/2012/10/14/2723541.html

二、手势UITapGestureRecognizer

UITapGestureRecognizer可以添加到任何的UIView控件上

// 默认是单指单机触发
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]   initWithTarget:self action:@selector(dismissKeyboard:)];
[self.view addGestureRecognizer:tap];
// tap.numberOfTapsRequired = 1; // 单击数
// tap.numberOfTouchesRequired = 1; // 手指数
...
- (void)dismissKeyboard:(UITapGestureRecognizer *)tap 
{
    // TODO
}

 

触摸事件和手势

标签:style   blog   http   color   io   ar   strong   sp   div   

原文地址:http://www.cnblogs.com/zw-h/p/4034989.html

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