【发布时间】:2014-11-08 15:11:05
【问题描述】:
我已经下载了适用于 iPhone 和 SDK 的 iOS 8 Gold Master。
我测试了这个应用程序,它运行良好,除了一件事。
我有一个文本字段,如果用户想要键入内容,则会出现一个数字键盘,此外,当键盘出现时,一个自定义按钮会添加到空白区域。
- (void)addButtonToKeyboard
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
// create custom button
UIButton * doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(-2, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(saveNewLead:) 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 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
}
到目前为止,这一切都很好。
首先,我收到以下警告:
找不到支持键盘类型 4 的键盘 iPhone-纵向-数字键盘;使用 3876877096_Portrait_iPhone-Simple-Pad_Default
然后那个自定义按钮也没有显示,我认为这是因为这两行:
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
和
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
有什么建议吗?
【问题讨论】:
-
对于从搜索引擎来到这里的人:本地化应用程序 (Xcode 11) 后出现错误。在模拟器应用程序的菜单中,取消选中:“I/O”>“键盘”>“使用与 macOS 相同的键盘语言”。我必须循环使用 Cmd-K / Cmd-Shift-K 才能让软键盘再次正常运行。