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. ES6高级技巧(三)

    html转译 let c='<a href="#">Me & you</a>'.replace(/[&<>'"]/g, ...

  2. 项目启动redis连接报错

    问题解决: 1)打开端口6379(修改iptabels文件) 2)关闭防火墙.(可能linux防火墙作用,限制了端口的出入) 3)修改redis.conf文件,将 bind 127.0.0.1这一行注 ...

  3. react 中 Modal 多次使用且带参数不同实现

    一.举例:对于 echatrs 的柱子分别需要弹窗 带参数 触发弹窗出现事件 showModalhref myChart.on('click', (params) => { switch (pa ...

  4. python 笔记——生成器和迭代器

    #-*- coding:utf-8 -*- a=[1,2,3,4] for i,j in enumerate(a): print i,j '''只有ij时,''' a=[1,2,3,4] for i ...

  5. B树和B+树的增/删结点(转)

    add by zhj: 算法其实不复杂,尤其是增加结点的算法,逻辑很简单,但有时自己想不到. 增加结点算法:首先,对于B树,没有重复结点,所以新插入的数据一定会落在叶结点上,或者说落在叶结点的所有父结 ...

  6. python装饰器的使用场景(转)

    原文:https://www.cnblogs.com/wupeiqi/articles/4980620.html 1.必备 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #### ...

  7. .Net Core 获取应用物理路径的常见问题

    如果要得到传统的ASP.Net应用程序中的相对路径或虚拟路径对应的服务器物理路径,只需要使用使用Server.MapPath()方法来取得Asp.Net根目录的物理路径. 但是在Asp.Net Cor ...

  8. hbase-indexer官网wiki

    Home Requirements Getting Started Installation Tutorial Demo Indexer Configuration CLI tools Metrics ...

  9. js-beautify 不换行

    最近在用Hbuilder-X,自带js-beautify.但是默认格式化设置实在是看着太难受.来看看一个VX的格式化,参数愣是给用了三行才格式化完,而且两个参数还分开了,看着太难受. // mutat ...

  10. 基于OpenGL三维软件开发

    实验原理: OpenGL在MFC下编程原理---- Windows操作系统对OpenGL的支持 在Windows下用GDI作图必须通过设备上下文(DeviceContext简写DC)调用相应的函数:用 ...