如何检测我们是否以编程方式关闭键盘并在uitextview中通过点击键盘关闭?

时间:2012-06-04 04:09:02

标签: ipad keyboard uitextview ios5

我需要获取此信息,如何检测我们是否以编程方式关闭键盘并在uitextview中通过点击键盘关闭?他们俩都叫

-(BOOL)textViewShouldEndEditing:(UITextView *)textView

但如何检测它的区别?有人能给我一些线索吗?

1 个答案:

答案 0 :(得分:1)

您可以创建通知观察者并监听某些事件:

UIWindow Class

// Each notification includes a nil object and a userInfo dictionary containing the
// begining and ending keyboard frame in screen coordinates. Use the various UIView and
// UIWindow convertRect facilities to get the frame in the desired coordinate system.
// Animation key/value pairs are only available for the "will" family of notification.
UIKIT_EXTERN NSString *const UIKeyboardWillShowNotification;
UIKIT_EXTERN NSString *const UIKeyboardDidShowNotification; 
UIKIT_EXTERN NSString *const UIKeyboardWillHideNotification; 
UIKIT_EXTERN NSString *const UIKeyboardDidHideNotification;

实施例

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@(keyboardDidDisappear)
                                             name:UIKeyboardDidHideNotification
                                           object:nil];