danielamitay / DAKeyboardControl

DAKeyboardControl adds keyboard awareness and scrolling dismissal (ala iMessages app) to any view with only 1 line of code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iPad Modal - Keyboard disappearing causes message view to move below modal lower bounds and out of view

opened this issue · comments

I am trying to use this library to handle a 'message bar' (similar to Messages). It works perfectly on the iPhone, but when used in an iPad modal, dismissing the keyboard causes the message bar to animate with it and once it hits the bottom of the modal view, it moves out of view.
Is there a way to ensure that the attached view respects the lower bounds of its superview when the keyboard is dismissing?

FYI - My message bar is just a UIView with a UITextView and UIButton.

Here is the fix. In a nutshell, just use a 'min()' function to determine if new frame is outside of the bounds of your containing view:

        self.view.addKeyboardNonpanningWithFrameBasedActionHandler({[unowned self] (keyboardFrameInView, opening, closing) -> Void in
            var toolbarFrame = self.messageToolbar.frame
            // Ensure message bar doesn't move outside of modal view's bounds
            toolbarFrame.origin.y = min(keyboardFrameInView.origin.y - toolbarFrame.size.height, self.view.frame.size.height - toolbarFrame.size.height)
            self.messageToolbar.frame = toolbarFrame
        }, constraintBasedActionHandler: nil)