ios-UIGesture扩展手势
来源:互联网 发布:华帝 方太 老板知乎 编辑:程序博客网 时间:2024/05/18 10:19
1、平滑手势
- (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"01"]]; imageView.frame=CGRectMake(0, 0, 200, 200); imageView.userInteractionEnabled=YES;//设置图像可交互 //创建一个平滑手势 UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panClick:)]; [imageView addGestureRecognizer:pan];//将手势添加到图像视图中 [self.view addSubview:imageView];}//只有手指按住屏幕在屏幕上运动的时候就会执行这个函数也就是说只要手指在屏幕上发生任何坐标变化都会调用该函数-(void)panClick:(UIPanGestureRecognizer *)pan{ //获取移动的坐标相对于该视图对象 CGPoint pt=[pan translationInView:self.view]; NSLog(@"pt.x=%.2f, pt.y=%.2f",pt.x,pt.y); //获取移动时的相对速度 CGPoint pv=[pan velocityInView:self.view];}在imageView中取消手势
[imageView removeGestureRecognizer:pan];
2、滑动手势
UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeClick:)]; //设置滑动手势接受事件的类型 swipe.direction=UISwipeGestureRecognizerDirectionLeft; //UISwipeGestureRecognizerDirectionLeft:向左滑动 //UISwipeGestureRecognizerDirectionRight:向右滑动 //UISwipeGestureRecognizerDirectionup:向上滑动 //UISwipeGestureRecognizerDirectionDown:向下滑动//我们这里也可以设置两个滑动手势 swipe.direction=UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;//如果我们只想添加一个点击函数的话,我们就要在这个点击函数中进行确定是滑向那一边的手势3、长按手势
UILongPressGestureRecognizer * longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(pressLong:)]; [imageView addGestureRecognizer:longPress]; //设置长按手势的时间,默认0.5s为长按手势,小于0.5秒的就为点击手势了 longPress.minimumPressDuration=0.5;-(void)pressLong:(UILongPressGestureRecognizer *)press{ //手指的状态对象,当长按达到0.5s的时候就会触发函数 if(press.state==UIGestureRecognizerStateBegan) { NSLog(@"状态开始"); } //当手指离开屏幕时就是结束状态 else if(press.state==UIGestureRecognizerStateEnded) { NSLog(@"结束状态"); }}
阅读全文
0 0
- ios-UIGesture扩展手势
- iOS开发从入门到精通--UIGesture手势扩展,平移,滑动,长按
- UIGesture 手势
- iOS开发从入门到精通--UIGesture手势基础
- iOS开发从入门到精通--UIGesture手势,图片的缩放和旋转
- UIGesture
- UIGesture
- IOS关闭和开启手势右滑扩展类
- iOS手势
- ios 手势
- IOS手势
- iOS手势
- iOS手势
- ios 手势
- iOS 手势
- iOS手势
- IOS手势
- iOS手势
- POJ
- 自定义MVC框架(分页前台部分)
- bzoj 4423: [AMPPZ2013]Bytehattan 并查集
- 扫盲系列—正向代理和反向代理
- 利用MOS管和稳压二极管来做保护电路
- ios-UIGesture扩展手势
- React Component 的生命周期 API
- 数组迭代器(一)-《数据结构预算法》
- gcc -fPIC 选项
- face++人脸识别接口实现原理(一)
- 技巧篇
- Insertion sort | Iterative & Recursive
- 一分钟了解“表示优点/缺点/特性 的词汇”
- (80)高级for循环(尤其是在集合中的简写形式)、可变参数、静态导入