Wil*_*ris 24 iphone uitextview uikeyboard ios4
我想在iPhone数字键盘键盘上添加一个完成按钮.左下方甚至还有一个方便的空间用于这样的按钮.
以前,我使用的问题与问题584538和Luzian Scherrer的优秀博客文章中描述的相似,但是在iOS 4中停止工作.我可以通过创建自定义inputView来实现,但我更喜欢扩展Apple的键盘而不是写我自己的.
是否有新方法将标准键盘添加到标准键盘?有人为此发布了OSS inputView吗?还有另外一种方法吗?
Lud*_*uda 89
您可以inputAccessoryView使用"应用"和"取消"按钮添加,然后关闭数字键盘.

- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个工作.请参阅此处的代码:http://gist.github.com/454844
有两个问题:
UIKeyboardWillShowNotification在键盘视图存在之前发送,但是您安排代码在下一个运行循环传递上运行,它们确实存在.所以你不必费心DidShow,在视觉上不那么讨人喜欢.
在iOS 4上,UIKeyboard视图位于视图层次结构的其他位置.
Luzian Scherrer 的博客文章 中描述的技术在 iOS 4.0 中确实有效。
我将按钮添加到键盘的代码失败了,因为它是从textFieldDidBeginEditing:委托方法调用的,该方法(在 4.0 中)是在创建键盘窗口的子视图之前调用的。我通过在观察到时调用我的代码来解决这个问题UIKeyboardWillShowNotification,这发生得足够晚了。
| 归档时间: |
|
| 查看次数: |
25347 次 |
| 最近记录: |