我的步骤:
- I从下面的代码中获取键盘视图(GetKeyboardView)
- I创建自定义视图,然后添加到键盘视图窗体(1.)
我有一个问题,为什么它在iOS8和以下版本上工作,但在iOS9中不工作。在iOS9中,键盘视图位于每个视图的顶部。如何解决这个问题?请给我推荐。
获取键盘视图的代码(它的工作)
-(UIView*)GetKeyboardView{
// locate keyboard view
int windowCount = (int)[[[UIApplication sharedApplication] windows] count];
if (windowCount < 2) {
return nil;
}
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([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES){
return keyboard;
}//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){
return keyboard;
}
}
}
}
return nil;
}
使用
UIWindow*tempWindow=[UIApplication sharedApplication].windows.lastObject;
而不是
UIWindow*tempWindow=[[UIApplication sharedApplication]windows]objectAtIndex:1];