gpt4 book ai didi

iOS 对自定义键盘设置了必需的高度限制

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:05:41 25 4
gpt4 key购买 nike

我正在尝试为 UITextField 创建自定义键盘。这不是系统扩展;它仅在我的应用程序中。

myTextField.inputView = CustomKeyboard()

CustomKeyboard 类具有 subview 和自动布局约束,需要比通常的系统键盘高一点。这会导致错误,因为系统正在添加必需的 customKeyboard.height == 216 约束。

如何告诉它不要添加此约束?它被添加到 CustomKeyboardsuperview 中的约束数组。

(lldb) po type(of: self)
MyApp.CustomKeyboard
(lldb) po self.superview!.constraints[0]
<NSLayoutConstraint:0x17428ab40 MyApp.CustomKeyboard:0x100d37580.height == 216 (active)>

最佳答案

我从 Apple 开发人员支持部门得到了答复。我已经实现了这个并且它有效。他们是这样说的:

If your inputView is using Auto Layout and has enough constraints such that it can determine its own height (which is the case in your example project), then all you need to do is override intrinsicContentSize in your input view and return a CGSize with a height that is not UIViewNoIntrinsicMetric. For example, this will do:

override var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: 0)
}

关于iOS 对自定义键盘设置了必需的高度限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42723179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com