iOS手势识别器
来源:互联网 发布:vb怎么添加下拉菜单 编辑:程序博客网 时间:2024/05/21 05:55
UIGestureRecognizer
UIGestureRecognizer类,用于检测丶识别用户使用设备时所用的手势.它是一个抽象类,定义了所有手势的基本行为.以下是UIGestureRecognizer子类,用于处理具体的用户手势行为:
UITapGestureRecognizer // 1.单击
UILongPressGestureRecognizer // 3.长按
UISwipeGestureRecognizer // 4.轻扫
UIPanGestureRecognizer // 5.移动
UIRotationGestureRecognizer // 6.旋转
UIPinchGestureRecognizer // 7.捏合
创建手势:
// 1.单击 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; [imgView addGestureRecognizer:tap]; // 2.双击 UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapAction:)]; doubleTap.numberOfTapsRequired = 2; [imgView addGestureRecognizer:doubleTap]; // 双击失败才单击 [tap requireGestureRecognizerToFail:doubleTap]; // 3.长按 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];//设置最短时间 longPress.minimumPressDuration = 1; [imgView addGestureRecognizer:longPress]; // 4.轻扫 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)]; // 设置轻扫方向 [swipe setDirection:UISwipeGestureRecognizerDirectionRight]; [imgView addGestureRecognizer:swipe]; // 5.移动 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [imgView addGestureRecognizer:pan]; // 轻扫失败才移动 [pan requireGestureRecognizerToFail:swipe]; // 6.旋转 UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)]; [imgView addGestureRecognizer:rotation]; // 7.捏合 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)]; [imgView addGestureRecognizer:pinch];
< GestureAction >
手势触发事件:
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress{ if (longPress.state == UIGestureRecognizerStateBegan) { NSLog(@"长按开始"); }else if (longPress.state == UIGestureRecognizerStateEnded){ NSLog(@"长按结束"); }}- (void)panAction:(UIPanGestureRecognizer *)pan { //手指所在的坐标 CGPoint point = [pan locationInView:self.view]; _view.center = point;}- (void)rotationAction:(UIRotationGestureRecognizer *)rotation{ if (rotation.state == UIGestureRecognizerStateChanged) { //取到弧度 CGFloat angle = rotation.rotation; //正在旋转 rotation.view.transform = CGAffineTransformMakeRotation(angle); } else if (rotation.state == UIGestureRecognizerStateEnded) { //还原 [UIView animateWithDuration:.5 animations:^{ rotation.view.transform = CGAffineTransformIdentity; }]; }}- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{ if (pinch.state == UIGestureRecognizerStateChanged) { // 取到缩放比率 CGFloat scale = pinch.scale; // 缩放 pinch.view.transform = CGAffineTransformMakeScale(scale, scale); } else if (pinch.state == UIGestureRecognizerStateEnded) { [UIView animateWithDuration:.5 animations:^{ pinch.view.transform = CGAffineTransformIdentity; }]; }}
< Motion 摇晃手势 >
//让当前对象成为第一响应者- (BOOL)canBecomeFirstResponder{ return YES;}- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"摇一摇开始");}- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"摇一摇结束");}
0 0
- iOS 手势识别器
- iOS手势识别器
- iOS手势识别器
- iOS 手势识别器
- UIGestureRecognizer iOS手势识别器
- iOS 手势识别器概述
- iOS UI05_手势识别器
- iOS常用手势识别器
- IOS开发:手势识别器
- iOS的手势识别器
- iOS开发之手势识别器
- iOS疯狂讲解之手势识别器
- iOS编程-------UIImageView、手势识别器UIGestureRecognizer
- iOS中事件产生、触摸、手势以及手势识别器
- iOS 手势识别 - gestureRecognizer
- ios 手势识别UIGestureRecognizer
- iOS 手势识别 - gestureRecognizer
- iOS手势识别初探
- sqlite 数据库更新
- Java基础学习总结——Java对象的序列化和反序列化
- Zero Copy初探
- initWithFrame 和 initWithCoder 区别
- UVa 895 - Word Problem
- iOS手势识别器
- Win7、Win8无法include stdio.h的解决方法
- Android实现全屏显示的方法
- mysql外键的使用详解
- 单点登录SSO的实现原理
- Flip Game【POJ--1753】【枚举】【高斯消元】
- Linux 常用命令
- Leetcode-201- Bitwise AND of Numbers Range
- seajs学习(4)----require 书写约定