美文网首页
UIResponder响应对象详解

UIResponder响应对象详解

作者: 浅_若清风 | 来源:发表于2018-05-22 13:46 被阅读0次

概述

ios中对UIResponder对象的定义是一个用于响应和处理事件的抽象接口

属性方法

1、管理响应器

//返回响应器链中的下一个响应器,或者如果没有下一个响应器,则为零

@property(nonatomic, readonly, nullable) UIResponder *nextResponder;

//返回接收下一个响应者,如果没有则为nil

- (nullableUIResponder*)nextResponder;

//是否为第一响应者

@property(nonatomic, readonly) BOOL isFirstResponder;

//返回一个布尔值指出接收者是否是第一个响应者

- (BOOL)isFirstResponder;

//是否可以成为第一响应者,默认为NO

@property(nonatomic, readonly) BOOL canBecomeFirstResponder;

//返回一个布尔值指出接收者是否可以成为第一响应者,默认为NO

- (BOOL)canBecomeFirstResponder;

//请求成为第一响应者

- (BOOL)becomeFirstResponder;

//是否愿意放弃第一响应者状态,默认为YES

@property(nonatomic, readonly) BOOL canResignFirstResponder;

//返回一个布尔值,指示接收者是否愿意放弃第一响应状态,默认为YES

- (BOOL)canResignFirstResponder;

//通知该对象它已被请求在窗口中放弃其作为第一响应者的状态

- (BOOL)resignFirstResponder;

2、响应触摸事件

//一根手指或多根手指触摸屏幕

- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event;

//一根手指或多根手指在屏幕上移动(随着手指的移动,相关的对象会持续发送该消息)

- (void)touchesMoved:(NSSet *)touches withEvent:(nullable UIEvent *)event;

//一根手指或多根手指离开屏幕

- (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event;

//在触摸操作正常结束前,某个系统事件(如有电话打进来)打断了触摸过程

- (void)touchesCancelled:(NSSet *)touches withEvent:(nullable UIEvent *)event;

//3D 触摸事件

- (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches NS_AVAILABLE_IOS(9_1);

3、响应运动事件

//开始运动

- (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event NS_AVAILABLE_IOS(3_0);

//结束运动

- (void)motionEnded:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event NS_AVAILABLE_IOS(3_0);

//取消运动

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event NS_AVAILABLE_IOS(3_0);

4、响应新闻事件

//开始按压物理按钮

- (void)pressesBegan:(NSSet *)presses withEvent:(nullable UIPressesEvent *)event NS_AVAILABLE_IOS(9_0);

//当按压相关联的值发生更改时,告知此对象(比如力值变化)

- (void)pressesChanged:(NSSet *)presses withEvent:(nullable UIPressesEvent *)event NS_AVAILABLE_IOS(9_0);

//释放物理按钮(不在按压)

- (void)pressesEnded:(NSSet *)presses withEvent:(nullable UIPressesEvent *)event NS_AVAILABLE_IOS(9_0);

//当系统事件(如低内存警告)取消按压事件时,告诉这个对象

- (void)pressesCancelled:(NSSet *)presses withEvent:(nullable UIPressesEvent *)event NS_AVAILABLE_IOS(9_0);

5、响应远程控制事件

//接收到远程控制事件时通知对象

- (void)remoteControlReceivedWithEvent:(nullable UIEvent *)event NS_AVAILABLE_IOS(4_0);

6、管理输入视图

//自定义输入视图(一般用于替换UITextField和UITextView对象呈现的系统提供的键盘)

@property (nullable, nonatomic, readonly, strong) __kindof UIView *inputView NS_AVAILABLE_IOS(3_2); 

//自定义输入视图控制器(一般用于替换UITextField和UITextView对象呈现的系统提供的键盘)

@property (nullable, nonatomic, readonly, strong) UIInputViewController *inputViewController NS_AVAILABLE_IOS(8_0);

//自定义输入附件视图(一般用于添加到UITextField和UITextView对象呈现的系统提供的键盘上)

@property (nullable, nonatomic, readonly, strong) __kindof UIView *inputAccessoryView NS_AVAILABLE_IOS(3_2);

//自定义输入附件视图控制器(一般用于添加到UITextField和UITextView对象呈现的系统提供的键盘上)

@property (nullable, nonatomic, readonly, strong) UIInputViewController *inputAccessoryViewController NS_AVAILABLE_IOS(8_0);

//当对象是第一个响应者时,更新自定义输入和附件视图

- (void)reloadInputViews NS_AVAILABLE_IOS(3_2);

7、获取撤消管理器

@property(nullable, nonatomic,readonly) NSUndoManager *undoManager NS_AVAILABLE_IOS(3_0);

8、验证命令

//请求接收响应器启用或禁用用户界面中的指定命令

- (BOOL)canPerformAction:(SEL)action withSender:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//返回响应操作的目标对象(标识与命令相关联的方法的选择器)

- (nullable id)targetForAction:(SEL)action withSender:(nullable id)sender NS_AVAILABLE_IOS(7_0);

8、访问可用的密钥命令

//响应器上触发动作的键命令

@property (nullable,nonatomic,readonly) NSArray *keyCommands NS_AVAILABLE_IOS(7_0); 

9、管理文本输入模式

//响应器对象的文本输入模式

@property (nullable, nonatomic, readonly, strong) UITextInputMode *textInputMode NS_AVAILABLE_IOS(7_0);

//响应器应保存其文本输入模式信息的标识符

@property (nullable, nonatomic, readonly, strong) NSString *textInputContextIdentifier NS_AVAILABLE_IOS(7_0);

//从应用程序的用户默认值清除文本输入模式信息

+ (void)clearTextInputContextIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(7_0);

//在配置键盘快捷键时使用的输入助手

@property (nonnull, nonatomic, readonly, strong) UITextInputAssistantItem *inputAssistantItem NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED;

10、支持用户活动

//封装由该响应器支持的用户活动的对象

@property (nullable, nonatomic, strong) NSUserActivity *userActivity NS_AVAILABLE_IOS(8_0);

//恢复继续给定用户活动所需的状态

- (void)restoreUserActivityState:(NSUserActivity *)activity NS_AVAILABLE_IOS(8_0);

//更新给定用户活动的状态

- (void)updateUserActivityState:(NSUserActivity *)activity NS_AVAILABLE_IOS(8_0);

11、标识符方法

//剪切

- (void)cut:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//拷贝

- (void)copy:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//粘贴

- (void)paste:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//选择

- (void)select:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//全选

- (void)selectAll:(nullable id)sender NS_AVAILABLE_IOS(3_0);

//删除

- (void)delete:(nullable id)sender NS_AVAILABLE_IOS(3_2);

// 居左

- (void)makeTextWritingDirectionLeftToRight:(nullable id)sender NS_AVAILABLE_IOS(5_0);

// 居右

- (void)makeTextWritingDirectionRightToLeft:(nullable id)sender NS_AVAILABLE_IOS(5_0);

//切换选定文本的粗体样式信息

- (void)toggleBoldface:(nullable id)sender NS_AVAILABLE_IOS(6_0);

//切换选定文本的斜体风格信息

- (void)toggleItalics:(nullable id)sender NS_AVAILABLE_IOS(6_0);

//切换选定文本的下划线样式信息

- (void)toggleUnderline:(nullable id)sender NS_AVAILABLE_IOS(6_0);

//增加选定文本或其他内容的大小

- (void)increaseSize:(nullable id)sender NS_AVAILABLE_IOS(7_0);

//减少选定文本或其他内容的大小

- (void)decreaseSize:(nullable id)sender NS_AVAILABLE_IOS(7_0);

12、支持的快捷键命令(keyCommands是UIResponder类在ios7后新增的一个只读属性)

typedef NS_OPTIONS(NSInteger,UIKeyModifierFlags) {   

 // Alppha+Shift键   

UIKeyModifierAlphaShift     = 1 <<16, 

 //Shift键   

UIKeyModifierShift          = 1 <<17, 

//Control键 

UIKeyModifierControl        = 1 <<18,     

 //Alt键   

UIKeyModifierAlternate      = 1 <<19, 

//Command键  

UIKeyModifierCommand        = 1 <<20,    

//Num键

UIKeyModifierNumericPad     = 1 <<21,  

}NS_ENUM_AVAILABLE_IOS(7_0);

//初始化对象

- (instancetype)init NS_DESIGNATED_INITIALIZER;

//初始化对象

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;

//输入字符串

@property (nonatomic,readonly) NSString *input;

//按键调节器

@property (nonatomic,readonly) UIKeyModifierFlags modifierFlags;

//按指定调节器键输入字符串并设置事件

@property (nullable,nonatomic,copy) NSString *discoverabilityTitle NS_AVAILABLE_IOS(9_0);

//创建一个快捷键命令

+ (UIKeyCommand *)keyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)modifierFlags action:(SEL)action;

//创建一个快捷键命令

+ (UIKeyCommand *)keyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)modifierFlags action:(SEL)action discoverabilityTitle:(NSString *)discoverabilityTitle NS_AVAILABLE_IOS(9_0); 

13、按键输入箭头指向

//上按键

UIKIT_EXTERN NSString *const UIKeyInputUpArrow         NS_AVAILABLE_IOS(7_0);

//下按键

UIKIT_EXTERN NSString *const UIKeyInputDownArrow       NS_AVAILABLE_IOS(7_0);

//左按键

UIKIT_EXTERN NSString *const UIKeyInputLeftArrow       NS_AVAILABLE_IOS(7_0);

//右按键

UIKIT_EXTERN NSString *const UIKeyInputRightArrow      NS_AVAILABLE_IOS(7_0);

//Esc按键

UIKIT_EXTERN NSString *const UIKeyInputEscape          NS_AVAILABLE_IOS(7_0);

相关文章

网友评论

      本文标题:UIResponder响应对象详解

      本文链接:https://www.haomeiwen.com/subject/rtkidftx.html