44.手势识别器
来源:互联网 发布:java redis 取list 编辑:程序博客网 时间:2024/05/23 13:08
1.单击手势: // 1.创建手势识别器 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; // 1.1设置手势识别器的属性 // 设置用户必须点击几次才能出发点击事件 tap.numberOfTapsRequired = 1; // 设置用户必须两根手指同时点击才会促发事件 tap.numberOfTouchesRequired = 1; // 2.添加手势识别器到view [self.iconView addGestureRecognizer:tap]; // 3.监听手势识别器 [tap addTarget:self action:@selector(tapView)];
2.长按手势: // 1.创建手势识别器 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] init]; // 1.1设置长按手势识别器的长按多长时间触发 longPress.minimumPressDuration = 1; // 手指按下后事件响应之前允许手指移动的偏移位 longPress.allowableMovement = 50; // 2.添加手势识别器到View [self.customView addGestureRecognizer:longPress]; // 3.监听手势识别器 [longPress addTarget:self action:@selector(longPressView)];
3.轻扫手势: // 向上 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] init]; // 设置轻扫的方向,默认从右向左(最多同时支持两个方向,用"|"隔开) swipe.direction = UISwipeGestureRecognizerDirectionUp; [self.customView addGestureRecognizer:swipe]; [swipe addTarget:self action:@selector(swipeView)];
4.旋转手势: UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] init]; [self.iconView addGestureRecognizer:gesture]; [gesture addTarget:self action:@selector(rotationView:)];- (void)rotationView:(UIRotationGestureRecognizer *)gesture{// 在传入的transform基础上递增一个弧度 self.iconView.transform = CGAffineTransformRotate(self.iconView.transform, gesture.rotation); // 将旋转的弧度清零(注意不是将图片旋转的弧度清零, 而是将当前手指旋转的弧度清零) gesture.rotation = 0;// 如果理解不了 , 记住就OK}
5.缩放手势: UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] init]; [self.iconView addGestureRecognizer:pinch]; [pinch addTarget:self action:@selector(pinchView:)];- (void)pinchView:(UIPinchGestureRecognizer *)pinch{ self.iconView.transform = CGAffineTransformScale(self.iconView.transform, pinch.scale, pinch.scale); pinch.scale = 1.0;//和旋转手势的原理一样}
6.拖拽手势: UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] init]; [self.customView addGestureRecognizer:pan]; [pan addTarget:self action:@selector(panView:)];- (void)panView:(UIPanGestureRecognizer *)pan{ // 返回的值是以手指按下的点为原点 CGPoint point = [pan translationInView:pan.view]; NSLog(@"拖拽事件 %@", NSStringFromCGPoint(point)); CGPoint temp = self.customView.center; temp.x += point.x; temp.y += point.y; self.customView.center = temp; // 理解不了就记住就OK [pan setTranslation:CGPointZero inView:pan.view];}
7.若要一个view同时支持多个手势,需要设置手势的代理并实现以下代理方法(返回是否同时支持多个手势):// 该方法返回的BOOL值决定了view是否能够同时响应多个手势- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ NSLog(@"%@ - %@", gestureRecognizer.class, otherGestureRecognizer.class); return YES;}
0 0
- 44.手势识别器
- 手势识别(一)手势识别器
- 手势识别器
- 手势识别器
- 33.手势识别器
- UI_GestureRecognizer_手势识别器
- UI04手势识别器
- 手势识别器(敲击)
- android手势识别器
- 手势识别器
- UIGestureRecognizer(手势识别器)
- 手势识别器
- 手势识别器
- 手势识别器(UIImageView)
- 手势识别器
- UI05_手势识别器
- UI05_手势识别器
- UI05_手势识别器
- EAN13条码在线生成器网址
- JS冒泡和闭包案例分析
- 日经社説 20150603 この甘さでは個人情報は守れない
- Android实战简易教程-第七枪(Activity的启动模式)
- 一个不错的解析URL地址的JS方法,推荐一下
- 44.手势识别器
- 当你在人间倦游的时候,请记得回来找我
- 前端面试题
- 社説 20150603 年金情報流出 サイバー攻撃への認識が甘い
- Algorithms—35.Search Insert Position
- redhat下安装squid
- select下拉选项分组<optgroup>
- Hadoop常见重要命令行操作及命令作用
- Jquery绑定事件(bind和live的区别)