0

我想在UITextField不关闭键盘的情况下失去焦点

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

所以,我想让键盘留在屏幕上而不是专注于UITextField. 当用户长按要复制的消息但 Viber 不会关闭键盘时,这就像 Viber。

4

2 回答 2

0

只需将下一个设置UITextField为第一响应者。

键盘不会消失,下一个文本字段将收到它的“击键”。

于 2013-02-20T06:44:05.183 回答
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");

 }

希望这可以帮助 !!!

于 2013-02-20T06:48:04.990 回答