键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default相关的知识,希望对你有一定的参考价值。
我已经为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];
}
}
}
}
到目前为止这个工作正常。
首先,我收到了这个警告:
键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default
那个自定义按钮也没有显示,我想因为这两行:
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
和
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
有什么建议?
我也有这个问题,并找到了解决方案。
以下是适用于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];
}
}
}
}
}
}
>
- (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;
}
}
希望这可以帮助。
但是,我仍然收到这个警告:
键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default
忽略这个警告,我得到了它的工作。如果你能从这个警告中得到解脱,请告诉我。
我使用分发配置文件时遇到了同样的问题。检查您是否使用开发者资料
为什么长代码而不使用UIToolbar?既然警告仍然存在?
UIToolbar适用于任何iOS版本,这是我的示例代码
UIToolbar *doneToolbar = [[UIToolbar alloc] initWithFrame:(CGRect){0, 0, 50, 50}]; // Create and init
doneToolbar.barStyle = UIBarStyleBlackTranslucent; // Specify the preferred barStyle
doneToolbar.items = @[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneEditAction)] // Add your target action
]; // Define items -- you can add more
yourField.inputAccessoryView = doneToolbar; // Now add toolbar to your field's inputview and run
[doneToolbar sizeToFit]; // call this to auto fit to the view
- (void)doneEditAction {
[self.view endEditing:YES];
}
在您的iOS应用程序中找不到连接到OS X的数字键盘。因此,您只需在模拟器中取消选中“连接硬件键盘”选项,在以下路径中仅用于测试目的:
Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard
这将解决上述问题。
我想你也应该看到以下链接。它说在论坛帖子结尾的
bug
中是XCode
!
也许你应该重置按钮的框架,我也有一些问题,并且nslog键盘视图如下:
iOS8上:
"<UIInputSetContainerView: 0x7fef0364b0d0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7fef0364b1e0>>"
before8:
"<UIPeripheralHostView: 0x11393c860; frame = (0 352; 320 216); autoresizesSubviews = NO; layer = <CALayer: 0x11393ca10>>"
好的,这是一个简单的解决方案,当我遇到类似的错误时,可以在iOS 9,iOS 8及以下版本的应用中显示和使用“完成”按钮。在运行应用程序并通过“View的层次结构”查看它(即,当应用程序在设备上运行并在Storyboard中检查您的视图时,单击调试区域栏中的“查看层次结构”图标)时,可以观察到键盘显示在与iOS 8及以下版本相比,iOS 9中的不同窗口必须加以考虑。 addButtonToKeyboard
- (id)addButtonToKeyboard
{
if (!doneButton)
{
// 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];
}
NSArray *windows = [[UIApplication sharedApplication] windows];
//Check to see if running below iOS 9,then return the second window which bears the keyboard
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
return windows[windows.count - 2];
}
else {
UIWindow* keyboardWithDoneButtonWindow = [ windows lastObject];
return keyboardWithDoneButtonWindow;
}
}
如果你愿意,这就是你如何从键盘中删除KeyboardButton。
- (void)removeKeyboardButton {
id windowTemp = [self addButtonToKeyboard];
if (windowTemp) {
for (UIView *doneButton in [windowTemp subviews]) {
if ([doneButton isKindOfClass:[UIButton class]]) {
[doneButton setHidden:TRUE];
}
}
}
}
更新到最新的Xcode Beta后,我也遇到了这个问题。刷新模拟器上的设置,因此正在检测笔记本电脑(外部)键盘。如果你只是按:
iOS模拟器 - >硬件 -
以上是关于键盘iPhone-Portrait-NumberPad找不到支持类型4的键盘;使用3876877096_Portrait_iPhone-Simple-Pad_Default的主要内容,如果未能解决你的问题,请参考以下文章