https://developer.apple.com/library/content/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/DirectingInputtoaSpecificResponder.html#//apple_ref/doc/uid/TP40009541-CH12-SW1

Directing Input to a Specific Responder

Touch events are automatically dispatched to the view in which they occurred, but most other events are directed to the object designated as the first responder. You can also set the first responder programmatically to any of your app’s responder objects. User interactions may also cause a view to become the first responder automatically, but only if it wants to be the first responder. For example, tapping a text field causes the text field to become the first responder, but tapping a button triggers the button’s action and does not cause it to become the first responder.

When an object becomes the first responder, UIKit displays the input view associated with that responder. An input view is a custom interface that you can use to gather information. The system keyboard is an example of an input view.

Programmatically Changing the First Responder

To designate an object as the first responder, call its becomeFirstResponder method. UIKit makes the object the first responder only if the following conditions are met:

  • The current first responder’s canResignFirstResponder property returns YES.

  • The new responder’s canBecomeFirstResponder property returns YES. (The default implementation of this property returns NO, so you must override it to allow your object to become the first responder.)

Most responder objects resign the first responder status readily, but you can return NO as needed from the canResignFirstResponder property. For example, you might return NO to prevent your custom control from resigning as first responder while it contains invalid data.

firstResponder的更多相关文章

  1. 解析iOS开发中的FirstResponder第一响应对象

    1. UIResonder 对于C#里所有的控件(例如TextBox),都继承于Control类.而Control类的继承关系如下: 代码如下: System.Object System.Marsha ...

  2. (转)FirstResponder 释放问题

    FirstResponder 释放问题 转自:http://www.cnblogs.com/smileEvday/archive/2012/03/18/2405190.html View的FirstR ...

  3. iOS 委托与文本输入(内容根据iOS编程编写)

    文本框(UITextField) 本章节继续编辑 JXHypnoNerd .文件地址 . 首先我们继续编辑  JXHypnosisViewController.m 修改  loadView 方法,向  ...

  4. iOS开发常用代码块

    遍历可变数组的同时删除数组元素 NSMutableArray *copyArray = [NSMutableArray arrayWithArray:array]; NSString *str1 = ...

  5. ios开发中的小技巧

    在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewal ...

  6. iOS对键盘的处理

    方法1. 使用<UITextFeildDelegate>,使用的UITextField示例 设置其Delegate为self,点击return按钮隐藏键盘.实现函数如下:    - (BO ...

  7. 深入浅出iOS事件机制

    原文地址: http://zhoon.github.io/ios/2015/04/12/ios-event.html 本文章将讲解有关iOS事件的传递机制,如有错误或者不同的见解,欢迎留言指出. iO ...

  8. [转]iOS7中UITextView contentsize改变时机

    在iOS7以下版本中,对UITextView设置了text属性,则contentsize就会变化,从而可以根据contentsize的变化来改变UITextView高度来做出TextView高度随着输 ...

  9. iOS小技巧总结,绝对有你想要的

    原文链接 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIV ...

随机推荐

  1. .net core 在 View 中使用 Jquery 无效问题

    问题描述: 在 View 视图中使用模板 _Layout.cshtml,其中模板已经调用了 Jquery.js ,但是在 View 视图下写 js 无效.后来通过浏览器查看自己写的 js 压根没加载出 ...

  2. spring Valid @Pattern 常见的验证表达式

    1 匹配首尾空格的正则表达式:(^\s*)|(\s*$)   2 整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$ 3 只能输入数字:"^[0-9]*$". 4 只 ...

  3. Sitecore 8.2 防火墙规则的权威指南

    如今,使用多层安全保护您的数据不再是奢侈品; 这是不容谈判的.此外,您需要确保Sitecore解决方案保持运行并与集成服务(例如SQL,Mongo,Solr)通信,同时保持相同的安全级别. 让我们假设 ...

  4. 算法:线性查找(重点isFlag标志)

    package com.atguigu; public class Main { public static void main(String[] args) { String[] arr=new S ...

  5. Java学习:单列集合Collection

    集合 学习集合的目标: 会使用集合存储数据 会遍历集合,把数据取出来 掌握每种集合的特性 集合和数组的区别 数组的长度是固定的.集合的长度是可变的. 数组中存储的是同一类型的元素,可以存储基本数据类型 ...

  6. pacman 命令详解

    Pacman 是一个命令行工具,这意味着当你执行下面的命令时,必须在终端或控制台中进行. 1.更新系统 在 Arch Linux 中,使用一条命令即可对整个系统进行更新:pacman -Syu 如果你 ...

  7. HTML中marquee标签的使用

    HTML5之前,marquee作为滚动标签被经常使用,具体用法如下: <marquee>默认向左滚动</marquee> 选项: 1.behavior 滚动的方式 altern ...

  8. 玩转zynq7020之风速风向测量实战项目

    本文是用米尔zynq7020开发板(Z-turn broad)风速风向测量实战项目. 这次项目是以测量风速风向为目标的产品,由于传统的风杯有很大的缺陷,在零下20度,结冰后不能使用,还有启动风速等等, ...

  9. phpStudy配置多站点多域名和多端口的方法

    切记:要想多个域名指向同一个项目,必须将phpstudy的根目录指向你项目所指的地方(原根目录是WWW),修改位置(其他菜单选项 - 软件设置 - 端口常规设置 - 网站目录) 站点:类似于  WWW ...

  10. xenserver增加新硬盘

    1. 查看所有硬盘了的id # ls -l /dev/disk/by-id/ 2. 挂载 # xe sr-create type=lvm content-type=user device-config ...