我已经为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];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这个工作正常.
首先,我收到了这个警告:
键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘; 使用3876877096_Portrait_iPhone-Simple-Pad_Default
那个自定义按钮也没有显示,我想因为这两行:
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
Run Code Online (Sandbox Code Playgroud)
和
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
Run Code Online (Sandbox Code Playgroud)
有什么建议?
aqu*_*lin 139
更新到最新的Xcode Beta后,我也遇到了这个问题.刷新模拟器上的设置,因此正在检测笔记本电脑(外部)键盘.如果你只是按:
iOS模拟器 - >硬件 - >键盘 - >连接硬件键盘
这样输入是UNchecked,然后软件键盘将再次显示.
小智 39
模拟器试图在Mac上找到一个数字小键盘,但找不到(MacBook Pro,MacBook Air和"普通/小型"键盘没有它).您可以取消选择"连接硬件键盘"选项,或者只是忽略错误消息,它对应用程序没有负面影响.
iGW*_*iGW 10
我也有这个问题,并找到了解决方案.
以下是适用于iOS 8.0以及以下版本的代码.
我在iOS 7和8.0(Xcode Version 6.0.1)上测试过它
- (void)addButtonToKeyboard
{
// create custom button
self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
//This code will work on iOS 8.3 and 8.4.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
self.doneButton.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 53, 106, 53);
} else {
self.doneButton.frame = CGRectMake(0, 163+44, 106, 53);
}
self.doneButton.adjustsImageWhenHighlighted = NO;
[self.doneButton setTag:67123];
[self.doneButton setImage:[UIImage imageNamed:@"doneup1.png"] forState:UIControlStateNormal];
[self.doneButton setImage:[UIImage imageNamed:@"donedown1.png"] forState:UIControlStateHighlighted];
[self.doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
int windowCount = [[[UIApplication sharedApplication] windows] count];
if (windowCount < 2) {
return;
}
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView *keyboard;
for (int i = 0; i < [tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
UIButton *searchbtn = (UIButton *)[keyboard viewWithTag:67123];
if (searchbtn == nil)
[keyboard addSubview:self.doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
UIButton *searchbtn = (UIButton *)[keyboard viewWithTag:67123];
if (searchbtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
[keyboard addSubview:self.doneButton];
} //This code will work on iOS 8.0
else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES) {
for (int i = 0; i < [keyboard.subviews count]; i++)
{
UIView *hostkeyboard = [keyboard.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) {
UIButton *donebtn = (UIButton *)[hostkeyboard viewWithTag:67123];
if (donebtn == nil)//to avoid adding again and again as per my requirement (previous and next button on keyboard)
[hostkeyboard addSubview:self.doneButton];
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
>
- (void)removedSearchButtonFromKeypad
{
int windowCount = [[[UIApplication sharedApplication] windows] count];
if (windowCount < 2) {
return;
}
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
for (int i = 0 ; i < [tempWindow.subviews count] ; i++)
{
UIView *keyboard = [tempWindow.subviews objectAtIndex:i];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3){
[self removeButton:keyboard];
} else if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
[self removeButton:keyboard];
} else if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES){
for (int i = 0 ; i < [keyboard.subviews count] ; i++)
{
UIView *hostkeyboard = [keyboard.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES) {
[self removeButton:hostkeyboard];
}
}
}
}
}
- (void)removeButton:(UIView *)keypadView
{
UIButton *donebtn = (UIButton *)[keypadView viewWithTag:67123];
if(donebtn) {
[donebtn removeFromSuperview];
donebtn = nil;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
但是,我仍然收到这个警告:
键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘; 使用3876877096_Portrait_iPhone-Simple-Pad_Default
忽略这个警告,我得到了它的工作.如果你能从这个警告中得到解脱,请告诉我.
小智 6
进入“模拟器”->“硬件”->“键盘”,然后取消选中“连接硬件键盘”。
在我退出并重新启动模拟器之前,与上面BUT上的许多答案相同,对我来说并没有改变。xcode 8.2.1和Simulator 10.0。
在您的 iOS 应用程序中找不到连接到 OS X 的数字键盘。因此您只需在模拟器中取消选中“连接硬件键盘”选项,以下路径仅用于测试目的:
Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard
Run Code Online (Sandbox Code Playgroud)
这将解决上述问题。
我想你也应该看看下面的链接。它说它是
bug
在XCode
该论坛帖子主题的末尾!