iOS11 not taking constraints correctly

前端 未结 2 1500
感动是毒
感动是毒 2020-12-22 07:40

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 ve

相关标签:
2条回答
  • 2020-12-22 08:08

    Swift

    Use IHKeyboardAvoiding

    Step 1) pod 'IHKeyboardAvoiding'

    Step 2) Copy the following code

     import IHKeyboardAvoiding
    
      override func viewDidAppear(_ animated: Bool) {
        KeyboardAvoiding.avoidingView = Your_View
      }
    
    0 讨论(0)
  • 2020-12-22 08:23

    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
    }
    
    0 讨论(0)
提交回复
热议问题