UIKit框架之UIGestureRecognizer
---恢复内容开始---
1.继承链:NSObject
2.UIGestureRecognizer的子类有以下:
UIScreenEdgePanGestureRecognizer :拖动,不过要从侧边拖动UILongPressGestureRecognizer :长按
3.想要使用手势一系列的行为需要遵守 UIGestureRecognizerDelegate协议
4.初始化手势识别器
(1)- (instancetype)initWithTarget:(id)target action:(SEL)action :为一个对象初始化和分配空间,并设定手势的行为
5.添加和移除target和行为
(1)- (void)addTarget:(id)target action:(SEL)action :为手势识别器对象添加一个target,并设定指定的行为
(2)- (void)removeTarget:(id)target action:(SEL)action :从手势识别器中移除指定的target和指定的action
6.获取手势的touches和位置
(1)- (CGPoint)locationInView:(UIView *)view :返回指定视图被触摸的位置
(2)- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view :触摸点相对于指定视图的位置
(3)- (NSUInteger)numberOfTouches :触摸点的数量
7.获取手势的状态和视图
(1)@property(nonatomic, readonly) UIGestureRecognizerStatestate :获取手势的状态
(2)@property(nonatomic, readonly) UIView*view :获取接受手势的视图
(3)@property(nonatomic, getter=isEnabled) BOOL enabled :手势是否可用
8.取消和延迟触摸
(1)@property(nonatomic) BOOL cancelsTouchesInView :取消视图的触摸
(2)@property(nonatomic) BOOL delaysTouchesBegan :延迟触摸的开始
(3)@property(nonatomic) BOOL delaysTouchesEnded :延迟触摸的结束
9.指定两个手势识别器的依赖
(1)- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer :只有当别的识别器触发失败的时候才使用该识别
10.设定委托
(1)@property(nonatomic, weak) id< UIGestureRecognizerDelegate> delegate :设定指定的委托
11.子类的方法
(1)- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event :触摸屏幕时开始执行这个方法
(2)- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event :触摸移动过程中执行这个方法
(3)- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event :触摸结束的时候执行这个方法
(4)- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event :当触摸因为意外情况而取消就会执行这个方法
(5)- (void)reset :重置手势
(6)- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event :忽略某个事件的手势
(7)- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer :重载这个方法能够执行UIGestureRecognizerDelegate协议里面的方法gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:.
(8)- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer :Overridden to indicate that the receiver can prevent the specified gesture recognizer from recognizing its gesture.
(9)- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer :重载这个方法来设定接收者不响应指定的手势
(10)- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer :重载这个方法来指定接收者应该被要求失败通过指定的手势识别器,Overridden to indicate that the receiver should be required to fail by the specified gesture recognizer.
(11)- (void)ignorePress:(UIPress *)button forEvent:(UIPressesEvent *)event :告诉手势识别器忽视按的事件
(12)- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event :当按钮被按的时候发送事件到接收者
(13)- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event :当按钮的压力变化的时候发送事件到接收者
(14)- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event :当按钮结束按的动作的时候发送事件给接收者
(15)- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event :当按钮的按动作被取消的时候发送事件到接收者
12.配置不同的手势
(1)@property(nonatomic, copy) NSArray<NSNumber *> *allowedPressTypes :一组不同按的类型来区分按钮被按
(2)@property(nonatomic, copy) NSArray<NSNumber *> *allowedTouchTypes :一组不同的触摸类型,用来区分不同的touches
13.数据类型
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
---恢复内容结束---
UIKit框架之UIGestureRecognizer的更多相关文章
- UIKit框架使用总结--看看你掌握了多少
一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
随机推荐
- WebStorm和sublime上使用git连接github(转)
WebStorm使用git连接github的方法: 用webstorm上传代码时,首先要先下载git,网址一搜就可以搜到,安装git,并且把ssh配置到github上.然后开始配置webstorm,打 ...
- cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...
- linux系统文件说明
linux系统文件说明 bin 系统命令目录 dev 设备目录 home 用户的家(每个系统用户在home下都有一个自己家) root超级用户在根目录下 lib 系统库目录.so动态库文件 media ...
- SharePoint 根据时间筛选
最近在整SP列表 老大要求用列表规范周报格式. 提出要在一个视图内查看上周一至周日的内容 翻了下资料想到了以下几种方法 1.在视图页面添加时间筛选器webpart,用参数传入列表筛选 2.在列表添加按 ...
- Java split()用法
特殊情况有 * ^ : | . \ 一.单个符号作为分隔符 String address="上海\上海市|闵行区\吴中路"; String[] splitAddress=addr ...
- js中setTimeout()时间参数设置为0的探讨
起因源于一道前端笔试题: var fuc = [1,2,3]; for(var i in fuc){ setTimeout(function(){console.log(fuc[i])},0); co ...
- Scala HandBook
目录[-] 1. Scala有多cool 1.1. 速度! 1.2. 易用的数据结构 1.3. OOP+FP 1.4. 动态+静态 1.5. DSL 1.6 ...
- mysql与sqlserver之间的关系转换
sqlserver中的数据类型与mysql之间的对应 --sqlserver = 只复制表结构 = 复制表结构和表数据 --mysql create table xx like xx; 只复制表结构 ...
- 聊聊css hack
什么是CSS hack CSS hack由于不同厂商的浏览器,比如Internet Explorer,Safari,Mozilla Firefox,Chrome等,或者是同一厂商的浏览器的不同版本,如 ...
- Bootstrap<基础十五> 输入框组
Bootstrap 支持的另一个特性,输入框组.输入框组扩展自 表单控件.使用输入框组,可以很容易地向基于文本的输入框添加作为前缀和后缀的文本或按钮. 通过向输入域添加前缀和后缀的内容,您可以向用户输 ...