简体   繁体   English

隐藏键盘iOS后的调用方法

[英]Call method after hiding keyboard iOS

I have textview on iPad. 我在iPad上有textview。 I have handled events on done click of textview. 我已经完成单击textview的事件。 But however iPad lower right hide keyboard button behaves differently on click. 但是,iPad的右下隐藏键盘按钮在单击时的行为有所不同。 It should call the same methods which are called in done click. 它应该调用与完成点击相同的方法。 However it doesn't happen. 但是这不会发生。 Is there any any other method which is called? 是否还有其他被称为的方法?

Pressing the "hide" button on the keyboard doesn't call the method you've set up to be called with the "Done" or "Return" key. 按下键盘上的“隐藏”按钮不会调用通过“完成”或“返回”键设置的方法。 Pressing the hide button calls resignFirstResponder on the keyboard, and hides it. 按下“隐藏”按钮将调用键盘上的resignFirstResponder并将其隐藏。

If you want your method to be called every time the keyboard is dismissed: 如果您希望每次关闭键盘时都调用您的方法:

First be aware for keyboard notifications 首先要注意键盘通知

Objective-C: Objective-C的:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillHideNotification object:nil];

Swift: 迅速:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);

then use 然后使用

Objective-C: Objective-C的:

- (void)keyboardDidHide: (NSNotification *) notification
{
    // Do something here
}

Swift: 迅速:

func keyboardDidHide(sender: NSNotification) 
{
    //Do something here
}

Check out the docs for using the keyboard , and UIResponder . 查看有关使用键盘UIResponder的文档。

You can try with this. 您可以尝试一下。

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if ([text isEqualToString:@""]) {
    //done button pressed
}
return YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM