iOS11 没有正确地接受约束

iOS11 not taking constraints correctly

我在商店中有一个应用程序,为了支持所有设备和键盘,我正在根据键盘高度更改底部约束高度。它适用于除 iOS11 之外的所有 iOS 版本。按钮没有改变它的位置,如下图所示。

谢谢!

这是 iOS10 预览

这是 iOS11 预览

代码

    func keyboardWillShow(notification: NSNotification) {
    if !keyboardIsHidden{
        return;
    }
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        keyboardIsHidden = false
        nextButtonBottmConstraint.constant = nextButtonBottmConstraint.constant + keyboardSize.height
    }
}

如果您使用 UIKeyboardWillShowNotification 获取键盘高度,请将 UIKeyboardFrameBeginUserInfoKey 更改为 UIKeyboardFrameEndUserInfoKey

UIKeyboardFrameBeginUserInfoKey returns 0 for keyboard rect height value in iOS 11. Changing it to UIKeyboardFrameEndUserInfoKey might solve this issue.

Objective-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
}

Swift

使用 IHKeyboardAvoiding

第 1 步)吊舱 'IHKeyboardAvoiding'

第二步)复制以下代码

 import IHKeyboardAvoiding

  override func viewDidAppear(_ animated: Bool) {
    KeyboardAvoiding.avoidingView = Your_View
  }