Background iOS 8自定义输入视图背景色

Background iOS 8自定义输入视图背景色,background,keyboard,ios8,Background,Keyboard,Ios8,我有一个自定义的输入视图,可以与iOS键盘交换。在iOS 8之前,对于iOS 7,我通过查找类UIKBInputBackdropView(包含在UIPeripheralHostView中)的子视图来“使用”键盘背景。然后,我能够设置背景视图的alpha,以获得清晰的自定义输入视图背景 对于iOS 8,这不再有效(我意识到它是不受支持的API,这就是风险)。通过一些实验和阅读,现在似乎可以在视图层次结构中找到自定义输入视图: UIInputSetContainerView->UIInputSetH

我有一个自定义的输入视图,可以与iOS键盘交换。在iOS 8之前,对于iOS 7,我通过查找类UIKBInputBackdropView(包含在UIPeripheralHostView中)的子视图来“使用”键盘背景。然后,我能够设置背景视图的alpha,以获得清晰的自定义输入视图背景

对于iOS 8,这不再有效(我意识到它是不受支持的API,这就是风险)。通过一些实验和阅读,现在似乎可以在视图层次结构中找到自定义输入视图:

UIInputSetContainerView->UIInputSetHost


看起来不再有背景视图在自定义输入视图后面提供不透明度。有人能告诉我如何摆脱自定义输入视图背后的半透明/模糊效果吗?

我在iOS 8上也遇到过同样的问题,有办法从输入视图中删除背景

- (void)removeKeyboardBackground
{
    // Locate non-UIWindow.
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }
    // Locate background.
    for (UIView *possibleFormView in [keyboardWindow subviews]) {
        if ([[possibleFormView description] hasPrefix:@"<UIInputSetContainerView"]) {
            for (UIView* peripheralView in possibleFormView.subviews) {
                if ([[peripheralView description] hasPrefix:@"<UIInputSetHostView"]) {
                    for (UIView* backSubiview in peripheralView.subviews) {

                    if ([[backSubiview description] hasPrefix:@"<UIKBInputBackdropView"]) {
                        [[backSubiview layer] setOpacity:0.0];
                    }
                }
                }

            }
        }
    }
}
-(无效)移除键盘背景
{
//找到非UIWindow。
UIWindow*键盘窗口=无;
对于(在[[UIApplication sharedApplication]windows]中的UIWindow*testWindow]){
如果(![[testWindow类]isEqual:[UIWindow类]]){
键盘窗口=测试窗口;
打破
}
}
//找到背景。
对于(UIView*在[keyboardWindow子视图]中可能的窗体视图){

如果([[possibleFormView description]hasPrefix:@“我在更高版本的iOS中使用了一个可接受答案的变体。看起来苹果现在已经将UIKBInputBackdropView推到了另一个UIView下:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:(v) options:NSNumericSearch] != NSOrderedAscending)

- (void)removeKeyboardBackground
{
    NSString *viewPath;

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0"))
        viewPath = @"UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIView/UIKBInputBackdropView";
    else
        viewPath = @"UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIKBInputBackdropView";

    NSArray *appWindows = [NSMutableArray arrayWithArray:[[UIApplication sharedApplication] windows]];
    NSArray *viewsFound = [self viewsFromViews:appWindows AtPath:[viewPath componentsSeparatedByString:@"/"]];

    for (UIView *background in viewsFound)
        background.layer.opacity = 0.0;
}

- (NSArray<__kindof UIView *> *)viewsFromViews:(NSArray<__kindof UIView *> *)views AtPath:(NSArray<NSString *> *)path
{
    NSMutableArray *viewsFound = [NSMutableArray array];

    if (views != nil && path != nil && [views count] > 0 && [path count] > 0)
    {
        NSString *prefix = [@"<" stringByAppendingString:[path firstObject]];
        NSArray *pathRemaining = [path count] <= 1 ? nil : [path subarrayWithRange:NSMakeRange(1, [path count] - 1)];

        for (UIView *view in views)
            if ([[view description] hasPrefix:prefix]) {
                if (pathRemaining == nil)
                    [viewsFound addObject:view];
                else
                    [viewsFound addObjectsFromArray:[self viewsFromViews:[view subviews] AtPath:pathRemaining]];
            }
    }

    return viewsFound;
}
#定义系统版本(大于)或(等于)(v)([[UIDevice currentDevice]systemVersion]比较:(v)选项:NSNumericSearch]!=传感器解除搜索)
-(无效)移除键盘背景
{
NSString*视图路径;
如果(系统版本大于或等于(@“11.0”))
viewPath=@“UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIView/UIKBInputBackdropView”;
其他的
viewPath=@“UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIKBInputBackdropView”;
NSArray*appWindows=[NSMutableArray阵列WithArray:[[UIApplication sharedApplication]windows]];
NSArray*viewsFound=[self-viewsFromViews:appWindows AtPath:[viewPath组件由字符串分隔:@”/“];
用于(UIView*viewsFound中的背景)
background.layer.opacity=0.0;
}
-(NSArray*)视图来自视图:(NSArray*)视图路径:(NSArray*)路径
{
NSMutableArray*viewsFound=[NSMutableArray];
如果(视图数!=nil&&path!=nil&&[views count]>0&&[path count]>0)
{

NSString*prefix=[@“您是在将加载自定义输入视图的主视图中使用此方法,还是在自定义输入视图本身中使用此方法?我尝试了这两种方法,但不幸的是,我仍然得到了灰色背景。非常感谢您的帮助!您找到了iOS9的解决方案吗?