iphone - UIMenuController和响应者链: what's going on?

标签 iphone ios uiview first-responder uimenucontroller

我在自定义 UIView 子类上使用 UIMenuController。这意味着它可以成为第一响应者,并在“删除”操作上声明它canPerformAction

我还希望此 View 的 super View (也是自定义 UIView)能够使用菜单 Controller ,因此在该 super View 上,我将其标记为能够成为第一响应者,并实现了 canPerformAction 用于不同的操作(在本例中为“复制”和“剪切”)。

事情是这样的——当我使菜单从(第一个) subview 可见时,它将所有三个操作都放在菜单中:删除、复制和剪切。在调试器中,我看到 canBecomeFirstRespondercanPerformAction 在菜单出现之前在两个 View 上被调用。

这是怎么回事?为什么菜单 Controller 不限制为第一响应者的 View ?或者我没有正确诊断这个问题?

谢谢。

最佳答案

您使用什么代码?

canPerformAction:withSender: 的文档中,

This default implementation of this method returns YES if the responder class implements the requested action and calls the next responder if it does not. ... Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command.

这似乎是矛盾的,说默认实现会递归响应者链,但如果返回 NO,UIMenuController 也会递归响应者链。

最简单的忽悠可能是覆盖 -nextResponder 以返回 nil,但这可能会产生其他副作用(例如,默认情况下,具有“nil”目标的操作会沿着响应者链向上! )。

关于iphone - UIMenuController和响应者链: what's going on?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7642181/

相关文章:

ios - 有没有办法在代码中获取 UIView 的框架(在 Storyboard 中创建)

ios - 自调整大小的表格 View 单元格不适用于 swift 中的 ExpandingTableView.framework 库

ios - UIActionSheet 事件未触发

ios - 分离约束和 UI 元素(UIView、UIButton、UITextField 等)声明以分离 swift 文件

ios - 滚动时选择行

iphone - self removeFromSuperView 不释放 self 吗?

ios - 在另一个动画之前在 alpha 上平滑地暂停重复的 UIView block 动画

iphone - 如何让 UICollectionViewFlowLayout 的单元格跨越多行?

iphone - 异步调用(特别是 iOS 地理编码)

ios - TableView 和 CollectionView 的位置和大小会自动在 iOS 的 Storyboard 中更改