iOS11 not taking constraints correctly

泪湿孤枕 提交于 2019-11-28 12:44:03

问题


I have an app on the store, in order to support all devices and keyboard I am changing the bottom constraint height according to keyboard height. It is working on all iOS versions except on iOS11. The button is not changing its place as it is shown in the below pictures.

Thank you!

this is iOS10 preview

this is iOS11 preview

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

回答1:


If you are using UIKeyboardWillShowNotification to get the keyboard height then change UIKeyboardFrameBeginUserInfoKey with 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
}


来源:https://stackoverflow.com/questions/46464528/ios11-not-taking-constraints-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!