我想在不解除键盘的情况下失去UITextField
的焦点
我有UITextField
和一些使用的对象可以长按以显示复制菜单。我使用UIMenuController
来显示菜单,然后它必须变为firstResponder => UITextField
将丢失编辑并关闭键盘。
所以,我想让键盘停留在屏幕上但不关注UITextField
。当用户长时间复制要复制的消息时,就像Viber一样,但Viber不会关闭键盘。
答案 0 :(得分:0)
只需将下一个UITextField
设置为第一响应者。
键盘不会消失,下一个文字字段会收到它的按键'。
答案 1 :(得分:0)
尝试使用UIkeyboard
的其他功能-(void)viewWillAppear:(BOOL)animated{
[txfield becomeFirstResponder];
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
NSLog(@"Keyboard");
}
- (void)keyboardWillHide:(NSNotification *)notification {
NSLog(@"NoKeyboard");
}
希望这有助于!!!