IOS手势操作:点击+滑动

简介: IOS手势操作:点击+滑动

1.手指点击事件

//单指单击
UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                  action:@selector(handleSingleFingerEvent:)];
singleFingerOne.numberOfTouchesRequired = 1; //手指数
singleFingerOne.numberOfTapsRequired = 1; //tap次数
singleFingerOne.delegate = self;
//单指双击
UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                  action:@selector(handleSingleFingerEvent:)];
singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
singleFingerTwo.delegate = self;
//双指单击
UITapGestureRecognizer *doubleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                  action:@selector(handleDoubleFingerEvent:)];
doubleFingerOne.numberOfTouchesRequired = 2;
doubleFingerOne.numberOfTapsRequired = 1;
doubleFingerOne.delegate = self;
UITapGestureRecognizer *doubleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                  action:@selector(handleDoubleFingerEvent:)];
doubleFingerTwo.numberOfTouchesRequired = 2;
doubleFingerTwo.numberOfTapsRequired = 2;
doubleFingerTwo.delegate = self;
//如果不加下面的话,当单指双击时,会先调用单指单击中的处理,再调用单指双击中的处理
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo];
//同理双指亦是如此
[doubleFingerOne requireGestureRecognizerToFail:doubleFingerTwo];
[self.view addGestureRecognizer:singleFingerOne];
[self.view addGestureRecognizer:singleFingerTwo];
[self.view addGestureRecognizer:doubleFingerOne];
[self.view addGestureRecognizer:doubleFingerTwo];
[singleFingerOne release];
[singleFingerTwo release];
[doubleFingerOne release];
[doubleFingerTwo release];
//处理单指事件
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender
{
    if (sender.numberOfTapsRequired == 1) {
        //单指单击
        NSLog(@"单指单击");
    }else if(sender.numberOfTapsRequired == 2){
        //单指双击
        NSLog(@"单指双击");
    }
}
//处理双指事件
- (void)handleDoubleFingerEvent:(UITapGestureRecognizer *)sender
{
    if (sender.numberOfTapsRequired == 1) {
        //双指单击
        NSLog(@"双指单击");
    }else if(sender.numberOfTapsRequired == 2){
        //双指双击
        NSLog(@"双指双击");
    }
}

2.手指滑动事件

UISwipeGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
    if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft||recognizer.direction==UISwipeGestureRecognizerDirectionDown) {
        NSLog(@"swipe left");
        //执行程序
        [self ReadNextPage];
    }
    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight||recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"swipe right");
        //执行程序
        [self ReadLastPage];
    }
}
相关文章
|
JSON 小程序 Android开发
小程序列表左滑效果在IOS呈上下滑动影响样式
小程序列表左滑效果在IOS呈上下滑动影响样式
131 0
|
3月前
|
iOS开发
iOS超出父控件范围无法点击问题
iOS超出父控件范围无法点击问题
144 58
|
3月前
|
iOS开发
iOS超出父控件范围无法点击问题
iOS超出父控件范围无法点击问题
|
7月前
|
Web App开发 移动开发 Android开发
解决IOS Safari浏览器H5页面上下滑动时卡顿、页面缺失的问题
解决IOS Safari浏览器H5页面上下滑动时卡顿、页面缺失的问题
|
7月前
|
Web App开发 前端开发 JavaScript
ios 系统滑动问题
ios 系统滑动问题
50 0
vue--ios手机input点击手机输入键盘顶起页面解决方案
vue--ios手机input点击手机输入键盘顶起页面解决方案
|
前端开发 JavaScript Android开发
【前端】IOS微信浏览器点击右上角遮罩实现
现在有一个需求,通过公众号或者链接,下载app应用,大家都知道,安卓和ios下载对应的版本都不一样。并且,ios 微信浏览器不支持应用下载,需要实现一个遮罩功能,提示用户通过浏览器下载,效果如下:
225 0
【前端】IOS微信浏览器点击右上角遮罩实现
|
移动开发 JavaScript Android开发
iOS12网页视频播放点击全屏按钮会导致闪退
iOS12网页视频播放点击全屏按钮会导致闪退
325 0
|
开发工具 iOS开发 git
iOS开发 - 类似美团选商品页,从按钮上往上滑动,tableview依然响应,点击按钮,按钮也可响应
iOS开发 - 类似美团选商品页,从按钮上往上滑动,tableview依然响应,点击按钮,按钮也可响应
220 0
iOS开发 - 类似美团选商品页,从按钮上往上滑动,tableview依然响应,点击按钮,按钮也可响应
|
iOS开发
iOS开发 - 滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)
iOS开发 - 滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)
234 0
iOS开发 - 滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)