在某些情况下尝试自动调整大小时,键盘扩展在iOS 10中会丢失高度 [英] Keyboard extension loses height in iOS 10 when trying to size automatically in some cases
问题描述
您可以在此下载展示此问题的示例项目:
iOS 10
这种布局正是我们所期望的。现在,让我们将新视图锚定到下一个键盘按钮的顶部。我们摆脱了刚刚添加的约束并用
anotherView.bottomAnchor.constraint替换它(equalTo:self.nextKeyboardButton.topAnchor ).isActive = true
逻辑上,生成的高度应该相同(由系统确定)
结果现在是:
iOS 9
iOS 10
开iOS 9的行为符合预期,但在iOS 10上,灵活的高度视图大小调整为0,剩下的就是固定高度按钮。
没有消息关于冲突的约束。我试图找出可能导致这种情况的原因以及为什么它只会发生在iOS 10上。
Apple已经回复我的DTS票并告诉我提交错误报告,所以这实际上是iOS 10的错误。我已经提交了一个雷达(#28532959),如果得到回复,我会更新这个答案。如果其他人提出了一个具体的解决方案,允许我仍然使用自动布局来达到自动高度,那么仍然可以接受答案。
You can download a sample project demonstrating the issue below here: https://github.com/DimaVartanian/keyboard-extension-height-bug
When creating a keyboard extension and not specifying a concrete height for its components but instead anchoring them to the view/inputView so that in theory the system will determine their height based on environment and orientation, in some situations that height instead turns into 0 and the keyboard is crushed (with the exception of anything that has a concrete height such as a self sized label or button).
This only seems to occur on iOS 10. On iOS 9, the child views resized correctly to fit the default automatic keyboard height.
There are several scenarios this can manifest and this project demonstrates a basic one. It starts with the basic keyboard extension template with the default "next keyboard" button and the 2 size constraints it comes with:
self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
Next, we create a single other view that we want to fill the space of the superview without defining a concrete size for itself:
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
Now, let's say we just want to anchor this new view to the bottom of our keyboard superview. We would just do something like:
anotherView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
The result looks like this:
iOS 9
iOS 10
This layout is exactly what we expect. Now instead, let's anchor the new view to the top of our next keyboard button. We get rid of the constraint we just added and replace it with
anotherView.bottomAnchor.constraint(equalTo: self.nextKeyboardButton.topAnchor).isActive = true
Logically, the resulting height should be the same (determined by the system)
The result is now this:
iOS 9
iOS 10
On iOS 9 it behaves as expected but on iOS 10, the flexible height view is resized down to 0 and all that is left is the fixed height button.
There are no messages about conflicting constraints. I'm trying to figure out what could be causing this and why it would only be happening on iOS 10.
Apple has responded to my DTS ticket and told me to file a bug report, so this is actually an iOS 10 bug. I have filed a radar (#28532959) and will update this answer if I ever get a response. If someone else comes up with a concrete solution that allows me to still use autolayout to achieve an automatic height, answers are still accepted.
这篇关于在某些情况下尝试自动调整大小时,键盘扩展在iOS 10中会丢失高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!