【发布时间】:2013-12-10 03:12:33
【问题描述】:
所以,小键盘键盘默认没有“完成”或“下一步”按钮,所以我想添加一个。在 iOS 6 及更低版本中,有一些技巧可以在键盘上添加按钮,但它们似乎不适用于 iOS 7。
首先我订阅了显示通知的键盘
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
然后我尝试在键盘出现时添加一个按钮:
- (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 的解决方案,所以我应该以不同的方式执行此操作吗?
编辑:感谢工具栏人员的所有建议,但我宁愿不走那条路,因为我的空间很差(而且有点难看)。
【问题讨论】:
-
试过这篇文章吗? neoos.ch/blog/…
-
@Anil 苹果禁止这种自定义UIKeyboard的方式。
-
检查 UIKeyboardDidShowNotification。
-
我不是很想添加工具栏,我想把按钮放在键盘上。
标签: ios iphone cocoa-touch uitextfield uikit