Ali*_*mze 29 iphone objective-c uitextfield
如何在编辑时更改iPhone上的返回键.我知道
myTextField.returnKeyType = UIReturnKeySearch;
Run Code Online (Sandbox Code Playgroud)
但是,这只有在我打电话[myTextField resignFirstResponder];然后[myTextField becomeFirstResponder];隐藏键盘然后将其带回来时才有效.否则,它只是保持我以前的那个,在这种情况下它是"Go".我需要根据用户输入的字符继续切换它们.
在一行中:如何在键盘编辑时更改键盘的返回键类型?
Mar*_*ton 56
[textField reloadInputViews] 似乎有把戏......
我找了一会儿,忘了回到这里.我在用:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:
(NSRange)range replacementString:(NSString *)string {
[self performSelector:@selector(addressBarTextDidChange:) withObject:nil afterDelay:0.1];
return YES;
}
-(void)addressBarTextDidChange:(NSString *)text {
NSString *addressText = @"..."; //Wherever you get your text from...
if ([addressText isEqualToString:@""]==NO) {
if ([addressText rangeOfString:@" "].location != NSNotFound) {
//[addressBarTextField setReturnKeyType:UIReturnKeySearch];
if (addressBarTextField.returnKeyType!=UIReturnKeySearch) {
[UIView beginAnimations:nil context:NULL]; //Setup the animation.
[UIView setAnimationDuration:0.0]; //The duration for the animation.
[addressBarTextField resignFirstResponder];
addressBarTextField.returnKeyType = UIReturnKeySearch;
[addressBarTextField becomeFirstResponder];
[UIView commitAnimations];
}
} else {
//[addressBarTextField setReturnKeyType:UIReturnKeyGo];
if (addressBarTextField.returnKeyType!=UIReturnKeyGo) {
[UIView beginAnimations:nil context:NULL]; //Setup the animation.
[UIView setAnimationDuration:0.0]; //The duration for the animation.
[addressBarTextField resignFirstResponder];
addressBarTextField.returnKeyType = UIReturnKeyGo;
[addressBarTextField becomeFirstResponder];
[UIView commitAnimations];
}
}
} else {
if (addressBarTextField.returnKeyType!=UIReturnKeyDone) {
[UIView beginAnimations:nil context:NULL]; //Setup the animation.
[UIView setAnimationDuration:0.0]; //The duration for the animation.
[addressBarTextField resignFirstResponder];
addressBarTextField.returnKeyType = UIReturnKeyDone;
[addressBarTextField becomeFirstResponder];
[UIView commitAnimations];
}
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我正在为键盘输入和输出动画持续0.0秒(因此用户将看不到它).我也在检查键盘是否已经是切换之前我想要的键盘因为不断切换导致滞后.
就我而言,它的工作原理如下:
sender.returnKeyType=UIReturnKeyNext;
[sender reloadInputViews];
[sender resignFirstResponder];
[sender becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)
我不得不强制使用risignFirstResponder,然后使用becomeFirstResponder.
| 归档时间: |
|
| 查看次数: |
8106 次 |
| 最近记录: |