R. Dewi
R. Dewi

Reputation: 4271

how to detect if we dismiss keyboard programmatically and dismiss by tap keyboard in uitextview?

i need to get this infomation, how to detect if we dismiss keyboard programmatically and dismiss by tap keyboard in uitextview? both of them called

-(BOOL)textViewShouldEndEditing:(UITextView *)textView

but how to detect it difference? can somebody give me some clue?

Upvotes: 0

Views: 449

Answers (1)

WrightsCS
WrightsCS

Reputation: 50707

You can create a notification observer and listen for certain events:

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;

Example

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

Upvotes: 1

Related Questions