[英]Height of custom keyboard in iOS and Swift 4
如何获得iOS给自定义键盘的视图高度?
我目前正在为iPhone 8 Plus手动设置键盘界面:
var keyboardHeight: CGFloat {
return UIScreen.main.bounds.height > UIScreen.main.bounds.width ? 226 : 162
}
如何以编程方式获取所有尺寸类别的键盘高度?
常见的方法是: 听键盘通知并对其进行响应 。
随通知一起发送的userInfo
词典的endFrame
键包含正确的键盘大小。 我还要考虑到最终的accessoryInputView
。
尝试这个
override func viewDidLoad() {
super.viewDidLoad()
let desiredHeight: CGFloat = 500
let heightConstraint = NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: desiredHeight)
view.addConstraint(heightConstraint)
self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.