0

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 ios10

this is iOS11 preview ios11

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
    }
}
Nagarjun
  • 6,557
  • 5
  • 33
  • 51
Tarek A.
  • 218
  • 2
  • 12

2 Answers2

4

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
}
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
  • my issue is not related keyboard since the code is working on all iOS versions except iOS 11 – Tarek A. Sep 28 '17 at 08:48
  • UIKeyboardFrameBeginUserInfoKey returns 0 for keyboard rect value in iOS 11. Changed it to UIKeyboardFrameEndUserInfoKey for a similar issue and it worked. – Mahesh De Silva Sep 28 '17 at 08:52
  • @KingT. As thm14 has said `UIKeyboardFrameBeginUserInfoKey` returns 0 for keyboard rect value in iOS 11. So `keyboardSize.height` is equal to 0. Changing `UIKeyboardFrameBeginUserInfoKey` with `UIKeyboardFrameEndUserInfoKey` will solve your problem. Try it – RajeshKumar R Sep 28 '17 at 09:40
  • @RajeshkumarR I will try it in a while and tell give feedback – Tarek A. Sep 28 '17 at 09:50
0

Swift

Use IHKeyboardAvoiding

Step 1) pod 'IHKeyboardAvoiding'

Step 2) Copy the following code

 import IHKeyboardAvoiding

  override func viewDidAppear(_ animated: Bool) {
    KeyboardAvoiding.avoidingView = Your_View
  }
Gaurav
  • 334
  • 6
  • 28