我在商店有一个应用程序,为了支持所有设备和键盘我根据键盘高度更改底部约束高度。除iOS11外,它适用于所有iOS版本。按钮没有改变它的位置,如下图所示。
谢谢!
CODE
func keyboardWillShow(notification: NSNotification) {
if !keyboardIsHidden{
return;
}
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
keyboardIsHidden = false
nextButtonBottmConstraint.constant = nextButtonBottmConstraint.constant + keyboardSize.height
}
}
答案 0 :(得分:4)
如果您使用UIKeyboardWillShowNotification
获取键盘高度,请使用UIKeyboardFrameBeginUserInfoKey
更改UIKeyboardFrameEndUserInfoKey
UIKeyboardFrameBeginUserInfoKey为键盘矩形高度返回0 iOS 11中的值可能会将其更改为UIKeyboardFrameEndUserInfoKey 解决这个问题。
<强>目标C 强>
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
//Change constraints
}
Swift 3
func keyboardWasShown(_ aNotification: Notification) {
let info = aNotification.userInfo
let kbSize: CGSize? = info?[UIKeyboardFrameEndUserInfoKey]?.cgRectValue?.size
//Change constraints
}
答案 1 :(得分:0)
快速
使用IHKeyboardAvoiding
第1步)广告连播“ IHKeyboardAvoiding”
第2步)复制以下代码
import IHKeyboardAvoiding
override func viewDidAppear(_ animated: Bool) {
KeyboardAvoiding.avoidingView = Your_View
}