OGeek|极客世界-中国程序员成长平台

标题: ios - 当点击 subview (UITextView)时调用superview的inputViewController [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:34
标题: ios - 当点击 subview (UITextView)时调用superview的inputViewController

我有 UIView 子类,我添加了一个 UITextField。我已将此 View 设置为我的 Viewcontroller 的顶 View 。 在 UIViewSubclass 中,我重写了 inputViewController getter 以提供自定义键盘。

当我选择 UITextField 时,我会假设 UITextFieldbecomeFirstResponder 被调用并且我会看到与之关联的键盘。 但是,除此之外,我的 UIView 子类 上的 inputViewController 方法也被调用,导致文本字段和 UIView 的输入 View 在另一个之上显示。我也没有看到 canBecomeFirstResponderbecomeFirstResponder 在我的 UIView 的子类 上被调用。仅调用 inputViewController 方法并显示自定义键盘。

谁能帮助我理解为什么 inputViewController 会在我的 UIView 的子类 上被调用,即使它没有成为第一响应者。

更新 从苹果文档 - “输入 View 是分配给 TextView 或自定义 View 的 inputView 属性的系统键盘的替代品。当有输入 View 时,即使文本对象是第一响应者,UIKit 也可能换掉键盘,它可能代表开发人员为非文本对象显示类似键盘的输入 View 。”

所以如果我理解正确的话,UIResponder 在我的 UIView 子类上调用 inputViewController 确实有意义,但理想情况下它应该用 inputViewController 替换文本字段键盘?显然,这并没有发生在这里。



Best Answer-推荐答案


您是否使用专门的 UIView 子类来覆盖 inputViewController?您可以尝试不这样做,而是将 UITextField 子类化,然后在您的 UITextField 子类中覆盖 inputViewController。

关于ios - 当点击 subview (UITextView)时调用superview的inputViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41604001/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4