在iPhone numpad iOS9上方添加自定义按钮

时间:2015-09-18 03:45:14

标签: iphone keyboard ios9

我们都知道如何在iPhone上方的普通数字键盘上添加自定义按钮(通常是“完成”)。与此相关的问题很少:

how to get keyboard location in ios 8 & add DONE button on numberPad

Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad; using 3876877096_Portrait_iPhone-Simple-Pad_Default

他们在iOS9之前工作正常。 iOS9破坏了现有的键盘视图层次结构,上面提到的解决方案不再适用。我花了几个小时试图找出差异,并决定在这里发布,因为它可能对其他人有用。

1 个答案:

答案 0 :(得分:1)

与适用于iOS7-8的解决方案的区别如下:

// Note index 2 here! In pre-iOS8 keyboard view panel was under second window after UIWindow, in iOS9 - they put some other views on the place and shifted everything one element down.
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows][2];
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:@"<UIPeripheralHostView"] == YES)
    {
        [keyboard addSubview:doneButton];
    }

}