因此,默认情况下,Numpad键盘没有"完成"或"下一步"按钮,所以我想添加一个.在iOS6及更低版本中,有一些在键盘上添加按钮的技巧,但在iOS7中似乎不起作用.
首先,我订阅显示通知的键盘
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
然后,当键盘出现时,我try 添加一个按钮:
- (void)keyboardWillShow:(NSNotification *)note
{
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
doneButton.frame = CGRectMake(0, 50, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(dismissKeyboard) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
但是for循环不会运行,因为它找不到任何子视图.有什么建议吗?我找不到任何针对iOS7的解决方案,那么有没有其他我应该这样做的方式呢?
编辑:感谢大家对工具栏的建议,但我不想走这条路,因为我的空间太小了(而且有点难看).