如何在不关闭键盘的情况下失去UITextField的焦点

时间:2013-02-20 06:39:28

标签: iphone ios cocoa uitextfield

我想在不解除键盘的情况下失去UITextField的焦点

我有UITextField和一些使用的对象可以长按以显示复制菜单。我使用UIMenuController来显示菜单,然后它必须变为firstResponder => UITextField将丢失编辑并关闭键盘。

所以,我想让键盘停留在屏幕上但不关注UITextField。当用户长时间复制要复制的消息时,就像Viber一样,但Viber不会关闭键盘。

2 个答案:

答案 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");

 }

希望这有助于!!!