firstResponder

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.

时间: 2024-10-28 15:54:10

firstResponder的相关文章

(转)FirstResponder 释放问题

FirstResponder 释放问题 转自:http://www.cnblogs.com/smileEvday/archive/2012/03/18/2405190.html View的FirstResponder的释放问题 今天遇到一个问题,当我隐藏掉一个正在接受用户输入的UITextField的时候,键盘并不会消失,而且键盘仍然接受用户输入,再次显示该TextField时候发现在隐藏状态下,所有的输入仍然传输到了该TextField中,于是查下官方资料找到如下解释: Important I

firstresponder 后,键盘不显示

问题:调用了firstresponder ,但键盘并没有显示,必须手动点击一下,才会显示键盘 分析:原入口进入是好的,自己新加了个window,从这个winodw的界面中点击进入就不显示了. 说明界面本身并没有问题,是自己新加的window导致了键盘弹不出 怀疑: 1.优先级 排除,因为如果是优先级的问题,点击触发也不会弹出 2.自己新建的窗口的界面中,没有释放掉firstResponder,导致UITextField获得不了 将自己窗口的界面中,所有界面元素在界面willdisappear的时

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

iOS 小技巧总结,绝对有你想要的 原文链接:http://www.jianshu.com/p/4523eafb4cd4 在这里总结一些 iOS 开发中的小技巧,能大大方便我们的开发,持续更新. —— 由 xcvxvxc分享 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 在viewWillAppear里面添加如下代码: //分组列表头部空白处理 CGRect frame = myTableView.tableHeade

UIResponder简要

关于UIResponder,我这边就简要的说一下响应链,firstResponder 1.响应链: 在UIResponder中有一个非常重要的概念叫做Responder Chain,个人的理解是这是按照一定规则组织的响应.处理事件的一条链表.在了解UIResponder之前还得在了解一个概念Hit-Testing.在IOS中通常使用hit-testing去找到那个被触摸的视图.这个视图叫hit-test view,当IOS找到hit-test view后就把touch event交个那个视图来处

UIControl

UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件. UIPageControl分页控件. 控件是对UIView派生类的实用增强及补充,并可以直接附着于导航栏.表格单元,甚至更大的对象. 这些控件的基类均是UIControl,而UIControl派生自UIView类,所以每个控件都有很多视图的特性,包括附着于其他视图的能力.所有 控件都拥有一套共同的属性和方法. 所以学习控件

**IOS:xib文件解析(xib和storyboard的比较,一个轻量级一个重量级)

使用Xcode做iOS项目,经常会和Xib文件打交道,因为Xib文件直观的展现出运行时视图的外观,所以上手非常容易,使用也很方便,但对于从未用纯代码写过视图的童鞋,多数对Xib的理解有些片面. Xib文件是什么? A nib file describes the visual elements of your application’s user interface, including windows, views, controls, and many others. It can also

Main.storyboard

Main.storyboard <?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5053" systemVers

Quartz2D练习 -- 裁剪图片分类

Main.storyboard <?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5053" systemVers

Quartz2D练习 -- 小黄人

Main.storyboard <?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5053" systemVers