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 ...
随机推荐
- CSS样式应用
CSS样式应用的方法: (1)行内样式,将css样式直接放到标签当中,一般都是放入标签的style属性中,它是最方便的一种样式,也是最不方便修改的样式.如下: (2)内嵌式,通过将css写在网页源文件 ...
- JAVA方法03之动手动脑问题解决
动手动脑1.当JAVA里定义的函数中去掉static后,怎么办?(如下程序,将square()函数的static去掉) public class SquareIntTest { public stat ...
- HTML/CSS总结1
1.定义网页背景颜色 <body bgcolor="背景色"> 颜色可以用2种方式表示:1. 直接指定颜色名称,如blue.2.使用十六进制数据表示如#RRGGBB,分 ...
- Mvc 提交表单的4种方法全程详解
一,MVC HtmlHelper方法 Html.BeginForm(actionName,controllerName,method,htmlAttributes){} BeginRouteForm ...
- SQL数据库索引查询
SELECT IA_ID,IA_Title,IT_ParentID,IA_Content,IA_CreateDate,IA_Author, )))) AS States FROM dbo.InfoAr ...
- mybatis高级(2)_数据库中的列和实体类不匹配时的两种解决方法_模糊查询_智能标签
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...
- CentOS_7.2服务器前期
一.禁用SELinux:# 永久禁用,需要重启生效: sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux se ...
- 【基本技能篇】>>第3篇《暗时间_指导学习的方法论——心得》
暗时间——指导学习的方法论 ——2016年2月11日 打造自己的核心竞争力:①专业领域技能:②跨领域的技能(解决问题的能力,创新思维,判断与决策能力,表达沟通能力等等):③学习能力,持续学习和思考新知 ...
- 常用的web功能测试方法
功能测试就是对产品各功能进行验证,根据功能测试用例,逐项测试,检查产品是否达到用户要求功能,即是否满足需求.常用的测试方法如下: 1.页面连接检查:每一个连接是否都有对应的页面,并且页面之间切换正确. ...
- jquery mobile 的优缺点
jQuery Mobile 优点 跨浏览器兼容性最好,几乎兼容所有的平台和浏览器: 入门简单,语法简洁,编码灵活,一些简单的应用直接用HTML既可实现,无需Javascript: 开源插件与第三方扩展 ...