IOS常用手势用法
2015-09-21 11:03
483 查看
target参数指的是给谁用手势,入button,view等
//1.单击
UITapGestureRecognizer *singleTapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
[self.buttonView addGestureRecognizer:singleTapGR];
- (void)singleTap:(UITapGestureRecognizer *)tap
{
NSLog(@"单击");
}
//2.双击
UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired=2;
[self.buttonView addGestureRecognizer:doubleTap];
//区别单击双击
[singleTapGR requireGestureRecognizerToFail:doubleTap];
//双击点击事件
-(void)doubleTap:(UITapGestureRecognizer *)taggestrue
{
NSLog(@"双击");
}
//3.轻扫
UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
//设置轻扫方向,默认向右
swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture];
//轻扫事件
-(void)swipe:(UISwipeGestureRecognizer *)swipeGesture
{
NSLog(@"轻扫手势");
}
//4.平移
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:panGesture];
-(void)pan:(UIPanGestureRecognizer *)pan
{
CGPoint point=[pan locationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(point));
}
//5.长按
UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longPressGesture.minimumPressDuration=1;
[self.buttonView addGestureRecognizer:longPressGesture];
-(void)longPress:(UILongPressGestureRecognizer *)longPress
{
//长按离开时一会调用一次,所以需要设置手势状态
if(longPress.state==UIGestureRecognizerStateEnded)
{
NSLog(@"UIGestureRecognizerStateEnded");
return;
}
NSLog(@"长按超过两秒");
}
//1.单击
UITapGestureRecognizer *singleTapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
[self.buttonView addGestureRecognizer:singleTapGR];
- (void)singleTap:(UITapGestureRecognizer *)tap
{
NSLog(@"单击");
}
//2.双击
UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired=2;
[self.buttonView addGestureRecognizer:doubleTap];
//区别单击双击
[singleTapGR requireGestureRecognizerToFail:doubleTap];
//双击点击事件
-(void)doubleTap:(UITapGestureRecognizer *)taggestrue
{
NSLog(@"双击");
}
//3.轻扫
UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
//设置轻扫方向,默认向右
swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture];
//轻扫事件
-(void)swipe:(UISwipeGestureRecognizer *)swipeGesture
{
NSLog(@"轻扫手势");
}
//4.平移
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:panGesture];
-(void)pan:(UIPanGestureRecognizer *)pan
{
CGPoint point=[pan locationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(point));
}
//5.长按
UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longPressGesture.minimumPressDuration=1;
[self.buttonView addGestureRecognizer:longPressGesture];
-(void)longPress:(UILongPressGestureRecognizer *)longPress
{
//长按离开时一会调用一次,所以需要设置手势状态
if(longPress.state==UIGestureRecognizerStateEnded)
{
NSLog(@"UIGestureRecognizerStateEnded");
return;
}
NSLog(@"长按超过两秒");
}
相关文章推荐
- 【转】iOS深入学习(Block全面分析)
- IOS 记录一些用到的正则表达式
- ios 错误
- iOS模拟器卡在启动界面
- iOS开发日记21-7.0之后的图文混排
- 七牛如何安装ios sdk (强烈建议试使用cocoapods安装)
- iOS 之旅--自定义开始界面
- iOS runtime方法详解之属性操作
- OC项目总结
- 银联手机支付控件官方使用指南(ios版)
- iOS APNS device Token 是否会改变?
- XCODE6+ios8真机调试[转]
- 七牛云存储xcode更新为ios9使用七牛的ios sdk上传报错
- iOS开发-zbar解析中文乱码情况
- iOS:转载FMDB文档
- iOS 小标签
- iOS stretchableImageWithLeftCapWidth 图片放大不变形
- iOS开发 xib错误 One" nib but the view outlet was not set
- iOS 百度地图SDK使用
- iOS开发脚踏实地学习day11-导航控制器