UIResponder详解

2024-06-13 03:08
文章标签 详解 uiresponder

本文主要是介绍UIResponder详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

UIResponder Class Reference

Managing the Responder Chain

[plain]  view plain copy
  1. 1.- (UIResponder *)nextResponder  
返回接收者的下一个相应,如果没有就返回nil

UIResponder类不自动存储和设置下一个响应者,而是默认返回nil。子类必须override这个方法来设置下一个响应者。

UIView实现了这个方法,因为可以返回管理这个UIView的UIViewController或者它的父类;

UIViewController实现了这个方法,返回UIViewController的View的父View;

UIWindow发挥UIApplication对象;

UIApplication返回nil

[plain]  view plain copy
  1. 2.- (BOOL)isFirstResponder  
判断一个对象是否是第一响应者。
[plain]  view plain copy
  1. 3.- (BOOL)canBecomeFirstResponder  
判断一个对象是否可以成为第一响应者。默认返回NO。

如果一个响应对象通过这个方法返回YES,那么它成为了第一响应对象,并且可以接收触摸事件和动作消息。

子类必须overrider这个方法才可以成为第一响应者。

You must not send this message to a view that is not currently attached to the view hierarchy. The result is undefined.

[plain]  view plain copy
  1. 3.- (BOOL)becomeFirstResponder  
如果接收者接受了第一响应者的状态就返回YES,拒绝了这个状态就返回NO。默认返回YES。

子类可以override这个方法来更新状态或者执行一些行为,比如高亮选中项。

一个响应对象只有当前响应者可以放弃第一响应者状态,并且新的响应者可以成为第一响应者,才能成为第一响应对象。

[plain]  view plain copy
  1. 4.- (BOOL)canResignFirstResponder  
如果一个对象可以放弃对象响应者就返回YES。默认返回YES。

[plain]  view plain copy
  1. 5.- (BOOL)resignFirstResponder  
默认实现返回YES,放弃第一响应状态。子类可以override这个方法来更新状态或者执行一些行为,比如取消高亮选中项。

如果返回NO,拒绝放弃第一响应状态。

如果你override这个方法,必须调用父类的实现[super resignFirstResponder].

Managing Input Views

[plain]  view plain copy
  1. 1.@property (readonly, retain) UIView *inputView  
当一个对象变成第一响应者的时候显示的View

This property is typically used to replace the system-supplied keyboard that is presented for UITextField and UITextView objects.

UITextField和UITextView如果设置了inputView那么在becomeFirstResponder时不会显示键盘,而现实自定义的inputView;如果设置了inputAccessoryView那么在becomeFirstResponder时会在键盘的顶端显示自定义的inputAccessoryView。

[plain]  view plain copy
  1. 2.@property (readonly, retain) UIView *inputAccessoryView  

This property is typically used to attach an accessory view to the system-supplied keyboard that is presented for UITextField and UITextView objects.

[plain]  view plain copy
  1. 3.- (void)reloadInputViews  
当对象成为第一响应者的时候更新inputView和accessoryView。

Responding to Touch Events

[plain]  view plain copy
  1. 1.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  
通知接收者当一个或多个手指在UIView或UIWindow上点下了。
将消息转发给下一个响应者,将消息发送给父类,不要将消息直接传递给下一个响应者。

如果你override这个方法而没有调用super..,你必须同样override其它响应触摸事件的方法,你要是空实现就好。

默认是不支持多点触摸的,如果想要响应多点触摸,你只要吧UIView的 multipleTouchEnabled 属性设置为YES即可。

[plain]  view plain copy
  1. 2.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  
手指移动
[plain]  view plain copy
  1. 3.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event  
手指抬起
[plain]  view plain copy
  1. 4.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event  
当收到一个系统干扰需要取消触摸事件时才会调用该方法,这种系统干扰往往会引起应用程序长时间没有响应或者一个View从window上移除了。
当收到touchesCancelled:withEvent:消息的时候需要清除所有通过touchesBegan:withEvent:创建的内容。

Responding to Motion Events

[plain]  view plain copy
  1. 1.- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event  
通知接收者一个动作开始了。
当一个动作开始了和结束了的时候iOS才会通知接收者。it doesn’t report individual shakes. 接收者必须是接收动作事件的第一响应者。
[plain]  view plain copy
  1. 2.- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event  
通知接收者一个动作结束了。
[plain]  view plain copy
  1. 3.- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event  
一个动作被取消了。雷同 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

Responding to Remote-Control Events

[plain]  view plain copy
  1. 1.- (void)remoteControlReceivedWithEvent:(UIEvent *)event  
接收到一个远程控制事件。比如耳机控制。
允许传递远程控制事件,必须调用UIApplication的beginReceivingRemoteControlEvents方法;关闭远程控制,调用endReceivingRemoteControlEvents。

Getting the Undo Manager

[plain]  view plain copy
  1. 1.@property(readonly) NSUndoManager *undoManager  
返回在响应链中最近的共享undo manager。
默认的,每个应用程序的window都有一个undo manager:a shared object for managing undo and redo operations.然而,在响应链中任何对象的类都有它们自己的undo manager,

Validating Commands

[plain]  view plain copy
  1. 1.- (BOOL)canPerformAction:(SEL)action withSender:(id)sender  

YES if the the command identified by action should be enabled or NO if it should be disabled. Returning YES means that your class can handle the command in the current context.

这篇关于UIResponder详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1056104

相关文章

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

spring中的ImportSelector接口示例详解

《spring中的ImportSelector接口示例详解》Spring的ImportSelector接口用于动态选择配置类,实现条件化和模块化配置,关键方法selectImports根据注解信息返回... 目录一、核心作用二、关键方法三、扩展功能四、使用示例五、工作原理六、应用场景七、自定义实现Impor

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

一文详解MySQL如何设置自动备份任务

《一文详解MySQL如何设置自动备份任务》设置自动备份任务可以确保你的数据库定期备份,防止数据丢失,下面我们就来详细介绍一下如何使用Bash脚本和Cron任务在Linux系统上设置MySQL数据库的自... 目录1. 编写备份脚本1.1 创建并编辑备份脚本1.2 给予脚本执行权限2. 设置 Cron 任务2

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

HTML5 搜索框Search Box详解

《HTML5搜索框SearchBox详解》HTML5的搜索框是一个强大的工具,能够有效提升用户体验,通过结合自动补全功能和适当的样式,可以创建出既美观又实用的搜索界面,这篇文章给大家介绍HTML5... html5 搜索框(Search Box)详解搜索框是一个用于输入查询内容的控件,通常用于网站或应用程

Python中使用uv创建环境及原理举例详解

《Python中使用uv创建环境及原理举例详解》uv是Astral团队开发的高性能Python工具,整合包管理、虚拟环境、Python版本控制等功能,:本文主要介绍Python中使用uv创建环境及... 目录一、uv工具简介核心特点:二、安装uv1. 通过pip安装2. 通过脚本安装验证安装:配置镜像源(可

C++ 函数 strftime 和时间格式示例详解

《C++函数strftime和时间格式示例详解》strftime是C/C++标准库中用于格式化日期和时间的函数,定义在ctime头文件中,它将tm结构体中的时间信息转换为指定格式的字符串,是处理... 目录C++ 函数 strftipythonme 详解一、函数原型二、功能描述三、格式字符串说明四、返回值五

LiteFlow轻量级工作流引擎使用示例详解

《LiteFlow轻量级工作流引擎使用示例详解》:本文主要介绍LiteFlow是一个灵活、简洁且轻量的工作流引擎,适合用于中小型项目和微服务架构中的流程编排,本文给大家介绍LiteFlow轻量级工... 目录1. LiteFlow 主要特点2. 工作流定义方式3. LiteFlow 流程示例4. LiteF