Keyboard “WillShow” and “WillHide” vs. Rotation

前端 未结 7 642
青春惊慌失措
青春惊慌失措 2021-01-31 04:56

I\'ve got a view controller listening for both UIKeyboardWillShowNotification and UIKeyboardWillHideNotification. The handlers for these notifications adjust various parts of th

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 05:19

    I know this a very very late reply. Now only I came on this situation and find the unanswered question. So I thought I'll share my solution. There will be some other better way, but the following way also we can solve this.

    The KBKeyboardHandler that I used is from: UITextField: move view when keyboard appears

    I just changed my delegate as following:

    - (void)keyboardSizeChanged:(CGSize)delta
    {    
        CGRect frame = self.view.frame;    
        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        switch (interfaceOrientation) {
            case UIInterfaceOrientationPortrait:
                frame.origin.y-=delta.height;
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                frame.origin.y+=delta.height;
                break;
            case UIInterfaceOrientationLandscapeLeft:
                frame.origin.x-=delta.height;
                break;
            case UIInterfaceOrientationLandscapeRight:
                frame.origin.x+=delta.height;
                break;
            default:
                break;
        }
        self.view.frame = frame;
    }
    

    And it was working fine.

提交回复
热议问题