0

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

-(BOOL)textViewShouldEndEditing:(UITextView *)textView

但如何检测它的差异?有人可以给我一些线索吗?

4

1 回答 1

1

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

UIWindow 类

// 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];
于 2012-06-04T04:16:19.733 回答