自定义 uiview 从 First Responder 辞职
我检查了与第一响应者相关的文档,但找不到当某些 UIView 退出第一响应者时收到的某种回调。让我解释一下我的情况。
因此,我有一个自定义 UIView (以编程方式创建),它在调用时成为第一个响应者。现在,当用户单击超级视图或其他视图时,我想关闭/删除此视图。我已经在超级视图中编写了逻辑,使其在收到触摸事件时成为第一响应者,但找不到该自定义视图的任何回调以在发生这种情况时将其关闭。
从另一个角度来看,我希望获得与文本字段键盘类似的行为,当其他视图成为第一响应者时,该键盘会被忽略。
我希望我的问题背景很清楚。
I checked the documentation related to First Responder but couldn't find some sort of callback which is received when some UIView resigns from being the first responder. Let me explain my scenario.
So, I have a custom UIView (created programmatically) which becomes the first responder when invoked. Now I want to dismiss/remove this view when the user clicks on the superview or some other view. I have written the logic in super view to make it as first responder when it receives a touch event but couldn't find any callback for that custom view to dismiss it when this happens.
Taking another view point I want to get a similar behavior as of the textfield's keyboard, which is dismissed when some other view becomes the first responder.
I hope my questions context is clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
UIView
继承自UIResponder
,因此您只需覆盖 resignFirstResponder 方法根据需要更新您的外观:Since
UIView
inherits fromUIResponder
, you can just override the resignFirstResponder method to update your appearance as necessary:我假设您在被触摸时已经实现了所有其他视图的 IBAction 方法。那么,如果您发现此自定义视图不为零并且不再需要,为什么不在这些方法中让此自定义视图退出第一响应程序,甚至被释放呢?
I assume you have implemented all the other view's IBAction methods when being touched. So why not in those methods let this custom view resign first responder or even be released if you find this custom view is not nil and is not needed anymore?