search

Home  >  Q&A  >  body text

IOS如何实现软键盘出现的时候,窗口的高度减少?(类似于聊天的窗口)

我想实现的效果就类似于微信或者手Q的聊天窗口,输入框在最底下,然后获得焦点时,软键盘弹出,但是此时聊天窗口的最顶上的内容还在,也就是聊天的窗口变成(手机屏幕-软键盘高度)。

思路或者demo代码或者github开源代码都OK

大家讲道理大家讲道理2892 days ago588

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:24:30

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
        

    Then just set the frame of the UI

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:24:30

    Are you talking about NavagationBar?
    If you are talking about this, then your problem will be solved. Just add a NavagationController to the first view as the rootController. This is very simple, but you still need to learn it

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:24:30

    Use notifications to monitor keyboard events, and then change the frame of the view. This is the idea of ​​​​2.

    reply
    0
  • Cancelreply