2013-12-10 41 views
1

我正在使用UITextView来捕获多行文本。我已将UIBarButtonItem添加到隐藏键盘的导航栏上的导航项目。如何显示键盘可见时的按钮

我只想让这个UIBarButtonItem按钮在键盘可见时出现。有没有办法检测键盘是否可见,并显示一个按钮时?

回答

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 
} 
相关问题