我有同样的问题。我假设您没有在绿色块上设置高度,因为您希望它填满键盘的剩余空间。如果您希望键盘具有恒定的高度,您可以简单地在绿色块上设置一个高度约束,您就完成了,但是由于屏幕尺寸和方向,您可能不希望所有东西都使用一个高度。
在 iOS 9 中,自定义键盘的默认大小与系统键盘相同。因此,如果您在 iOS 9 中运行它,绿色块会根据这些尺寸填充剩余空间。在 iOS 10 中由于某种原因没有默认高度,并且因为您的绿色块没有高度限制,它认为高度为零。
要修复它,您需要为键盘设置一个高度。这是我为处理它而编写的代码(到目前为止还不错)。将它放在 ViewDidLoad 之前的 keyboardviewcontroller 类中,你应该很高兴:
//***************************
//create constraint variable before function
var constraint = NSLayoutConstraint()
//function to set height
func setKeyboardHeight () {
let screenSize = UIScreen.mainScreen().bounds.size
let screenH = screenSize.height;
self.view.removeConstraint(constraint)
//you can set the values below as needed for your keyboard
if screenH >= 768 {
//for iPad landscape or portrait
self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 300.0)
self.view.addConstraint(self.constraint)
} else if screenH >= 414 {
//for iPhone portrait AND iPhone Plus landscape or portrait
self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 220.0)
self.view.addConstraint(self.constraint)
} else {
//for iPhone landscape
self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 140.0)
self.view.addConstraint(self.constraint)
}
}
//sets height when keyboard loads
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
setKeyboardHeight()
}
//sets or changes height when device rotates
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
setKeyboardHeight()
}
//***************************