ios - 在某些情况下尝试自动调整大小时,键盘扩展在 iOS 10 中丢失高度

标签 ios cocoa-touch autolayout ios10 ios-keyboard-extension

您可以在此处下载演示以下问题的示例项目: https://github.com/DimaVartanian/keyboard-extension-height-bug

在创建键盘扩展时,不为其组件指定具体高度,而是将它们锚定到 View /输入 View ,这样理论上系统将根据环境和方向确定它们的高度,在某些情况下,高度会变成0 并且键盘被压扁(具有具体高度的任何东西除外,例如自定大小的标签或按钮)。

这似乎只发生在 iOS 10 上。在 iOS 9 上, subview 会正确调整大小以适应默认的自动键盘高度。

这可以体现在多个​​场景中,这个项目演示了一个基本场景。它从基本的键盘扩展模板开始,带有默认的“下一个键盘”按钮和它附带的 2 个大小限制:

self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true

接下来,我们创建一个单独的其他 View ,我们想要填充父 View 的空间而不为自己定义具体大小:

let anotherView = UIView()
anotherView.backgroundColor = UIColor.red
anotherView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(anotherView)
anotherView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
anotherView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
anotherView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true

现在,假设我们只想将这个新 View 锚定到键盘 super View 的底部。我们会做类似的事情:

anotherView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true

结果是这样的:

iOS 9 enter image description here

iOS 10 enter image description here

这个布局正是我们所期望的。现在,让我们将新 View 锚定到下一个键盘按钮的顶部。我们摆脱了我们刚刚添加的约束并将其替换为

anotherView.bottomAnchor.constraint(equalTo: self.nextKeyboardButton.topAnchor).isActive = true

从逻辑上讲,得到的高度应该是一样的(由系统决定)

现在的结果是这样的:

iOS 9 enter image description here

iOS 10 enter image description here

在 iOS 9 上,它的行为符合预期,但在 iOS 10 上,灵活高度 View 的大小被调整为 0,剩下的就是固定高度按钮。

没有关于约束冲突的消息。我试图找出可能导致此问题的原因以及为什么它只会在 iOS 10 上发生。

最佳答案

Apple 已回复我的 DTS 请求并告诉我提交错误报告,因此这实际上是一个 iOS 10 错误。我已经提交了一个雷达 (#28532959),如果我得到回复,我会更新这个答案。如果其他人提出了一个具体的解决方案,允许我仍然使用自动布局来实现自动高度,答案仍然被接受。

关于ios - 在某些情况下尝试自动调整大小时,键盘扩展在 iOS 10 中丢失高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39694039/

相关文章:

ios - ASP.net Bootstrap 4 Navbar Input Caret Issue 仅限 iOS

html - Safari Ipad 视频透明但存在

ios - 判断 UITableView 是否已经滚动到顶部

ios - 如何以编程方式快速设置自动布局中的 UIView 大小?

ios - subview Controller 向下移动

php - 适用于 iOS 的简单 PHP/MySQL Web 服务

ios - iOS 5和Three20 SDK

ios - SpriteKit SKAction 缓动

ios - 刷新 UIPageViewController - 重新排序页面并添加新页面

swift - 长按使用约束更新放大