手势UIGestureRecognizer
UIGestureRecognizer抽象类,六大手势是其子类;
- UITapGestureRecognizer 点击
- UIPinchGestureRecognizer 缩放
- UIRotationGestureRecognizer 旋转
- UISwipeGestureRecognizer 轻扫
- UIPanGestureRecognizer 拖动
- UILongPressGestureRecognizer 长按
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) {//手势当前的状态
UIGestureRecognizerStatePossible, (默认)
UIGestureRecognizerStateBegan, (开始)
UIGestureRecognizerStateChanged,(已经改变)
UIGestureRecognizerStateEnded, (结束)
UIGestureRecognizerStateCancelled, (取消)
UIGestureRecognizerStateFailed, (失败)
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
}
一、拖动手势 UIPanGestureRecognizer
UIPanGestureRecognizer *panGesture =[[UIPanGestureRecognize alloc] initWithTarget:self action:@selection(handlePan:)];
[view addGestureRecognizer:panGesture];
- (void)handlePan:(UIPanGestureRecognizer *)panGesture{
CGPoint translation = [panGesture translationInView:self.view];
CGPoint point = CGPointMake(panGesture.view.center.x + translation.x,panGesture.view.center.y + translation.y);
panGesture.view.center = point;
[panGesture setTranslation:CGPointZero inView:self.view];
}
1、确保view是可交互的 view.userInteractionEnabled = yes;
2、translationInView (相对点击点的偏移量) locationInView(相对屏幕实时坐标);
3、setTranslation:CGPointZero inView(每次初始化位置) 和translationInView同时使用;
4、velocityInView (获取速度矢量)
二、捏合手势 UIPinchGestureRecognizer
UIPinchGestureRecognizer *phinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget: self action:@selector(handlePinch:)];
[view addGestureRecognizer:pinchGesture];
- (void)handlePinch:(UIPinchGestureRecognizer *)recognizer{
CGFloat scale = recognizer.scale;
recognizer.view.transform = CGAffineTransformMakeScale(scale, scale);// 每次缩放都回复原来基础下变化
// recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, scale, scale);//在已经缩放大小基础下累加变化
// recognizer.scale = 1.0;
}
scale 缩放倍数 ,velocity 缩放速率;
三、旋转手势 UIRotationGestureRecognizer
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotaton:)];
[view addGestureRecognizer:rotationGesture];
- (void)handleRotation:(UIRotationGestureRecognizer *)recognizer {
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = 0.0;
}
四、点击手势 UITapGestureRecognizer
@property (nonatomic) NSUInteger numberOfTapsRequired; // 点击次数(默认一次)
@property (nonatomic) NSUInteger numberOfTouchesRequired __TVOS_PROHIBITED; // 需要手字数(默认一个点击点)
五、长按手势 UILongPressGestureRecognizer
@property (nonatomic) NSUInteger numberOfTapsRequired; // Default is 0. The number of full taps required before the press for gesture to be recognized
@property (nonatomic) NSUInteger numberOfTouchesRequired __TVOS_PROHIBITED; // Default is 1. Number of fingers that must be held down for the gesture to be recognized @property (nonatomic) CFTimeInterval minimumPressDuration; // Default is 0.5. 最小长按时间
@property (nonatomic) CGFloat allowableMovement; // Default is 10. 长按时允许移动的距离
六、轻扫手势 UISwipeGestureRecognizer
typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
UISwipeGestureRecognizerDirectionRight = << ,
UISwipeGestureRecognizerDirectionLeft = << ,
UISwipeGestureRecognizerDirectionUp = << ,
UISwipeGestureRecognizerDirectionDown = <<
};
@property(nonatomic) UISwipeGestureRecognizerDirection direction; //轻扫方向
号外:同时响应多种手势
设置手势delegate实现方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
手势UIGestureRecognizer的更多相关文章
- 点击事件touches与ios的手势UIGestureRecognizer
.h文件 @property (weak,nonatomic) IBOutlet UILabel *messageLabel;@property (weak,nonatomic) IBOutlet U ...
- [BS-25] IOS中手势UIGestureRecognizer概述
IOS中手势UIGestureRecognizer概述 一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touches ...
- iOS手势UIGestureRecognizer的使用失效问题
问题:视图正常展示在界面中,父层是放在window上的,底部的一个控件的点击事件失效(所有设置都正常) 解决思路:虽然视图能够正常展示,但是发现父类视图的底部尺寸比子类的视图的尺寸小,也就是说上层视图 ...
- IOS手势UIGestureRecognizer
UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有6个子类处理具体的手势: 1.UITapGestureRecognizer (任意手指任意次数的点击) // 点击次数 ...
- 使用iOS手势UIGestureRecognizer
UIKit中包含了UIGestureRecognizer类,用于检测发生在设备中的手势.UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有下面一些子类用于处理具体的手势 ...
- 屏蔽手势UIGestureRecognizer 先后响应
在iOS5一下对于手势的识别能力并不强,比如iOS6上面按钮的一个tap事件,最先接收的是uiview,并相应,而不是最上面的button,这时候就需要判断手势所在的位置和手势所在的控制器了 如下例子 ...
- iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】
转自:iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 关于手势的一篇很好的帖子,转载过来免得丢失.你可能最感兴趣的是手势间的互斥处理,那么就搜索 4.手势间的互斥处 ...
- IOS中手势UIGestureRecognizer
通常在对视图进行缩放移动等操作的时候我们可以用UIScrollView,因为它里边自带了这些功能,我们要做的就是告诉UIScrollView的几个相关参数就可以了 但是没有实现旋转的手势即UIRota ...
- 关于iOS的手势UIGestureRecognizer问题
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { UIGestureRecognizerStatePossible, // 尚未识别是何种手 ...
随机推荐
- 纯css制作三级菜单
<!DOCTYPE html> <html> <head> <title>三级菜单</title> <meta charset=&qu ...
- javascript小技巧-js小技巧收集(转)
本文转载自:http://blog.csdn.net/ocean20/article/details/2498699 每一项都是js中的小技巧,但十分的实用! 1.document.write(&qu ...
- 【学术篇】SPOJ QTREE 树链剖分
发现链剖这东西好久不写想一遍写对是有难度的.. 果然是熟能生巧吧.. WC的dalao们都回来了 然后就用WC的毒瘤题荼毒了我们一波, 本来想打个T1 44分暴力 然后好像是特判写挂了还是怎么的就只能 ...
- PHP算法之整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 3: 输入: 120输出: 21注 ...
- case in
#!/bin/bash source /etc/profilesource ~/.bashrc #自己定义$version_number case $version_number in3.0.17) ...
- 校园商铺-4店铺注册功能模块-8店铺注册之Controller层的改造
不合理的地方: 1. 并不需要将InputStream转换成File类型,直接将InputStream传进入交给CommonsMultipartfile去处理就可以了 如果做这样的转换,每次都需要生成 ...
- ZuulFilter
在服务网关中定义过滤器,只需要继承ZuulFilter抽象类,实现其定义的四个抽象函数,就可对请求进行拦截与过滤 过滤器两个功能: 路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入 ...
- python多线程,event,互斥锁,死锁,递归锁,信号量
Python多线程/event 多线程-threading python的thread模块是⽐较底层的模块, python的threading模块是对thread做了⼀些包装的, 可以更加⽅便的被使⽤ ...
- thinkphp 异常处理
和PHP默认的异常处理不同,ThinkPHP抛出的不是单纯的错误信息,而是一个人性化的错误页面,如下图所示: 只有在调试模式下面才能显示具体的错误信息,如果在部署模式下面,你可能看到的是一个简单的提示 ...
- 0919CSP-S模拟测试赛后总结
60分-rank36,不出所料又炸了. 总是试图稳住成绩,但就是不能避免这样的大起伏.这样不行啊. T1可是道sb题啊……对着题干yy了一个多小时,正解基本都想到了,只差一个结构体排序. 然而即使我真 ...