UILongPressGestureRecognizer的介绍
2015-11-14 11:48
363 查看
首先UILongPressGestureRecognizer是继承自UIGestureRecognizer
所有的手势都是继承自UIGestureRecognizer
UIView *longPressView = [[UIView
alloc]init];
longPressView.backgroundColor = [UIColor
redColor];
longPressView.frame =
CGRectMake(100,
200, 100, 100);
[self.view
addSubview:longPressView];
创建一个长按的手势
这个方法是UIGestureRecognizer的方法
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc]initWithTarget:self
action:@selector(longPress:)];
为这个view添加手势
[self.view
addGestureRecognizer:longPress];
longPress.minimumPressDuration =
4;
The minimum period fingers must press on the view for the gesture to be recognized.
设置长按手势
最低多少秒后触发的时间,默认的是0.5秒
这个数值是按秒计算的
longPress.numberOfTouchesRequired =
1;
The number of fingers that must be pressed on the view
for the gesture to be recognized
设置几个手指来触发这个长按手势
默认是1
一般都是1
若为0
则不触发
longPress.numberOfTapsRequired =
0;
The number of taps on the view required for the gesture to be recognized
在这个view上手势需要识别轻敲击的次数
设置为1
就以为着连续快速的点击1次离开屏幕在迅速的点击这个view长按
不放到minimumPressDuration
才会触发手势的方法
默认是0
就是按住不放 不需要离开屏幕
longPress.allowableMovement =
20;
The maximum movement of the fingers on the view before the gesture fails
这个属性不是手势开始之后滑动的最大距离
只要UIGestureRecognizerStateBegan
你可以滑动任意大的距离
这是属性是刚刚开始触摸view的时候到UIGestureRecognizerStateBegan这时时间内
最大的滑动距离
默认是10
这个方法是触发这个手势后进入的方法 有兴趣的孩纸可以玩玩
-(void)longPress:(UILongPressGestureRecognizer *)longPress{
if (longPress.state ==
UIGestureRecognizerStateBegan) {
NSLog(@"longPressBegan");
}else
if (longPress.state ==
UIGestureRecognizerStateChanged){
NSLog(@"longPressChange");
}else
if (longPress.state ==
UIGestureRecognizerStateEnded){
NSLog(@"end");
}
}
所有的手势都是继承自UIGestureRecognizer
UIView *longPressView = [[UIView
alloc]init];
longPressView.backgroundColor = [UIColor
redColor];
longPressView.frame =
CGRectMake(100,
200, 100, 100);
[self.view
addSubview:longPressView];
创建一个长按的手势
这个方法是UIGestureRecognizer的方法
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc]initWithTarget:self
action:@selector(longPress:)];
为这个view添加手势
[self.view
addGestureRecognizer:longPress];
longPress.minimumPressDuration =
4;
The minimum period fingers must press on the view for the gesture to be recognized.
设置长按手势
最低多少秒后触发的时间,默认的是0.5秒
这个数值是按秒计算的
longPress.numberOfTouchesRequired =
1;
The number of fingers that must be pressed on the view
for the gesture to be recognized
设置几个手指来触发这个长按手势
默认是1
一般都是1
若为0
则不触发
longPress.numberOfTapsRequired =
0;
The number of taps on the view required for the gesture to be recognized
在这个view上手势需要识别轻敲击的次数
设置为1
就以为着连续快速的点击1次离开屏幕在迅速的点击这个view长按
不放到minimumPressDuration
才会触发手势的方法
默认是0
就是按住不放 不需要离开屏幕
longPress.allowableMovement =
20;
The maximum movement of the fingers on the view before the gesture fails
这个属性不是手势开始之后滑动的最大距离
只要UIGestureRecognizerStateBegan
你可以滑动任意大的距离
这是属性是刚刚开始触摸view的时候到UIGestureRecognizerStateBegan这时时间内
最大的滑动距离
默认是10
这个方法是触发这个手势后进入的方法 有兴趣的孩纸可以玩玩
-(void)longPress:(UILongPressGestureRecognizer *)longPress{
if (longPress.state ==
UIGestureRecognizerStateBegan) {
NSLog(@"longPressBegan");
}else
if (longPress.state ==
UIGestureRecognizerStateChanged){
NSLog(@"longPressChange");
}else
if (longPress.state ==
UIGestureRecognizerStateEnded){
NSLog(@"end");
}
}
相关文章推荐
- 进击的KFC:UI(三)自定义视图、视图控制器
- iOS开发小技巧:刷新UITableView
- 出现以下错误的解决方案 Assigning to ‘id<UINavigationControllerDelegate,UIImagePickerControllerDelegate…
- UIView与CALayer的详细区别
- UI 第三天 自定义视图 视图控制器
- query ui draggable,droppable
- 进击的KFC:UI(二)基础视图、程序启动流程
- ANDROID L——Material Design详解(UI控件)
- codeforces - Queries on a String(模拟+取余)
- 随意细解:UI -- 基础视图、程序启动流程
- UI基础-基础视图、程序启动流程
- 3.UITextField(输入框)知识总结
- 豆浆机改装记(7): 关于UI界面的构思
- Java String StringBuilder StringBuffer
- 2.UILabel(文本视图)知识总结
- LeetCode "Range Sum Query 2D - Immutable"
- 我的iOS学习历程 - UITouch(触摸反应)
- 我的iOS学习历程 - UITouch(触摸反应)
- robot-framework 源码阅读 之 suite name 搜索匹配
- 黑马程序员_JavaSE基础知识总结十七:GUI界面