6

I am developing a chat application which does have a toolbar(with UITextView and other buttons) at the bottom of chat screen same as whatsapp which moves up and down depending on keyboard visibility, which was working fine till iOS 7.

I have used UIKeyboardDidChangeFrameNotification based on which i used to fetch the keyboard frame using below code

  CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

and set the frame of toolbar accordingly.

but it is not working on iOS 8 with predictive text. Any Help appreciated.

EDIT:

UIKeyboardDidChangeFrameNotification not getting fired up when predictive text view moved up or down.

Appending snapshots

Image with predictive text enter image description here

njyulan
  • 43
  • 8
Pankaj Wadhwa
  • 3,073
  • 3
  • 28
  • 37
  • Have you test with Xcode6.1 beta? I don't see any deprecated in UIKeyboardDidChangeFrameNotification for iOS8 – LE SANG Sep 20 '14 at 07:58
  • I don't know what happened but when i deleted the derived data and restarted the Xcode then it started working.... – Pankaj Wadhwa Sep 20 '14 at 08:54
  • Take a look at my solution in the link: http://stackoverflow.com/questions/26213681/ios-8-keyboard-hides-my-textview/26226732#26226732 – newton_guima Oct 07 '14 at 00:37
  • @newton_guima problem already solved buddy. Thanks anyways.. – Pankaj Wadhwa Oct 07 '14 at 11:32
  • @pankaj Please post the solution you arrived at by answering your own question so that others (like myself) can benefit from how you ended up solving this. Thanks. – devios1 May 25 '15 at 21:29
  • @devios as i have mentioned above in comments that when i deleted all derived data from Xcode then my problem goes away. Still i have posted an answer to help others as how this functionality is done. Check it out here http://stackoverflow.com/a/25956919/1606125 – Pankaj Wadhwa May 26 '15 at 06:48
  • @pankaj Sorry I missed that! – devios1 May 26 '15 at 06:51

1 Answers1

-1

iOS 10, 9 all the way down to 5

UIKeyboardDidChangeFrameNotification

Posted immediately after a change in the keyboard’s frame.

The notification object is nil. The userInfo dictionary contains information about the keyboard. Use the keys described in Keyboard Notification User Info Keys to get the location and size of the keyboard from the userInfo dictionary.

Tested on iPhone 6, iOS 10, 9, 8.4 (linked, built, ran, see logs below).

The NSNotification dictionary shows the inversion of CGRect values in UIKeyboardFrameBeginUserInfoKey & UIKeyboardFrameEndUserInfoKey, and all 4 UIKeyboard__Notification are fired when the predictive accessory view is changed.

Swift 3

func addObserver(forName: Notification.Name) {
    NotificationCenter.default.addObserver(forName: forName,
                                           object: nil,
                                           queue: OperationQueue.main)
    { (note:Notification!) -> Void in
        print("\(forName): \(note)")
    }
}

addObserver(forName: .UIKeyboardWillShow)
addObserver(forName: .UIKeyboardDidShow)
addObserver(forName: .UIKeyboardWillChangeFrame)
addObserver(forName: .UIKeyboardDidChangeFrame)

Turning Predictive ON

enter image description here

log:

UIKeyboardWillChangeFrameNotification:
UIKeyboardWillShowNotification:
UIKeyboardDidChangeFrameNotification:
UIKeyboardDidShowNotification:
userInfo = { UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 554.5}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 442}, {375, 225}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}"; }

Turning Predictive OFF

enter image description here

log:

UIKeyboardWillChangeFrameNotification:
UIKeyboardWillShowNotification:
UIKeyboardDidChangeFrameNotification:
UIKeyboardDidShowNotification:
userInfo = { UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 225}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 538}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 554.5}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 409}, {375, 258}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 442}, {375, 225}}"; }


► Find this solution on GitHub and additional details on Swift Recipes.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179