我已经为 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-Portrait-NumberPad 的键盘;使用 3876877096_Portrait_iPhone-Simple-Pad_Default
然后那个自定义按钮也没有显示,我认为这是因为这两行:
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
和
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
有什么建议么?
更新到最新的 Xcode Beta 后,我也遇到了这个问题。模拟器上的设置已刷新,因此正在检测笔记本电脑(外部)键盘。如果您只需按:
iOS 模拟器 -> 硬件 -> 键盘 -> 连接硬件键盘
以便取消选中该条目,然后将再次显示软键盘。
模拟器尝试在 mac 上查找数字小键盘,但没有找到(MacBook Pro、MacBook Air 和“普通/小型”键盘没有)。您可以取消选择连接硬件键盘选项或忽略错误消息,它不会对应用程序产生负面影响。
只是去
iOS 模拟器 -> 硬件 -> 键盘 -> 取消选中连接硬件键盘选项。
这将解决问题。
执行上述步骤后,您的 MAC 键盘将无法使用,您必须使用模拟器键盘。
我在 ios 8 中使用 xcode,只需取消选中 Simulator-> Hardware-> Keyboard-> Connect Hardware Keyboard 中的连接硬件键盘选项。
这将解决问题。
我也遇到了这个问题并找到了解决方案。
下面是适用于 iOS 8.0 和以下版本的代码。
我已经在 iOS 7 和 8.0(Xcode 版本 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;
}
}
希望这可以帮助。
但是,我仍然收到此警告:
找不到支持类型 4 的键盘 iPhone-Portrait-NumberPad 的键盘;使用 3876877096_Portrait_iPhone-Simple-Pad_Default
忽略这个警告,我得到了它的工作。请让我知道你是否能从这个警告中解脱出来。
进入 Simulator-> Hardware->Keyboard 并取消选中 Connect Hardware Keyboard。
与上面的许多答案相同,但在我退出并重新启动模拟器之前,我并没有改变。 xcode 8.2.1 和模拟器 10.0。
我在 Xcode 8.1 和 iOS 10.1 中遇到了同样的问题。对我有用的是进入模拟器->硬件->键盘并取消选中连接硬件键盘。
使用模拟器运行应用程序
iOS Simulator-> Hardware-> Keyboard -> iOS 使用与 OS X 相同的布局
如果有人在他们的设备上运行他们的应用程序,这将解决问题
在您的 iOS 应用程序中找不到连接到您的 OS X 的数字小键盘。因此您只需要取消选中模拟器中的连接硬件键盘选项,在以下路径中仅用于测试目的:
Simulator -> Hardware -> Keyboard -> Connect Hardware Keyboard
这将解决上述问题。
我想你也应该看到下面的链接。它说这是该论坛帖子线程末尾的 XCode 中的错误!参考
由于两个不同的原因,我收到了相同的错误消息,因此您可以将它们添加到调试清单中:
上下文:Xcode 6.4,iOS:8.4。我正在添加一个带有自定义 UIBarButton
的工具栏,以使用 UIKeyboardTypeNumberPad
(Swift: UIKeyboardType.numberPad
) 加载,即“完成”和“+/-”。我在以下情况下遇到了这个问题:
我的 UIToolbar 被声明为属性,但我忘记显式分配/初始化它。我已经离开了最后一行,[myCustomToolbar sizeToFit];,这听起来和霍尔顿的回答是同一个家族(我的代码在这里:https://stackoverflow.com/a/32016397/4898050)。
祝你好运
我在使用分发配置文件时遇到了同样的问题。检查您是否使用开发者资料
为什么长代码而不使用 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];
}
我在使用 Flutter 时遇到了这个问题,当我点击我的输入时,键盘没有出现,我通过将 Form 小部件所在的小部件升级到 stateFull 来修复它。
但警告仍然存在。
也许你应该重置按钮的框架,我也遇到了一些问题,然后像这样 nslog 键盘的视图:
IOS8:
"<UIInputSetContainerView: 0x7fef0364b0d0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7fef0364b1e0>>"
之前8:
"<UIPeripheralHostView: 0x11393c860; frame = (0 352; 320 216); autoresizesSubviews = NO; layer = <CALayer: 0x11393ca10>>"
好的,当我遇到类似错误时,这是一个简单的修复方法,用于在 iOS 9、iOS 8 及更低版本的应用程序中显示和运行“完成”按钮。在运行应用程序并通过“视图的层次结构”查看它(即,当应用程序在设备上运行并检查您在 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];
}
}
}
}
不定期副业成功案例分享