键盘可见时如何显示按钮

时间:2013-12-10 12:42:02

标签: uitextview uibarbuttonitem uikeyboard

我正在使用UITextView来捕获多行文本。我已将UIBarButtonItem添加到隐藏键盘的导航栏上的导航项。

我只想在键盘可见时显示这个UIBarButtonItem按钮。有没有办法检测键盘何时可见并显示按钮?

1 个答案:

答案 0 :(得分:2)

使用以下方法:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
                                             name:UIKeyboardWillShowNotification object:self.view.window]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
                                             name:UIKeyboardWillHideNotification object:self.view.window]; 

然后你可以显示隐藏按钮:

- (void)keyboardWillShow:(NSNotification *)notif
{
      // code for show hide button
}

- (void)keyboardWillHide:(NSNotification *)notif
{
   // code for show hide button
}