iOS 7上的UITextView的inputView [英] UITextView's inputView on iOS 7

查看:86
本文介绍了iOS 7上的UITextView的inputView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为UITextField创建自定义键盘,此inputView的背景应该是透明的,我已将视图的xib文件中的背景颜色设置为clear color。它在iOS 6及更早版本上运行良好..但在iOS 7上它不工作
任何想法我怎么能让它工作?我希望它完全透明

I'm trying to create a custom keyboard for a UITextField, the background of this inputView should be transparent, I have set the background color in the view's xib file to "clear color". It is working great on iOS 6 and earlier.. but on iOS 7 it not working Any idea how can I make it work? I want it to be fully transparent

推荐答案

这会在显示自定义键盘时将背景不透明度设置为零并将其重置为1显示普通键盘时。

This will set the backdrops opacity to zero when displaying your custom keyboard and reset it back to 1 when the normal keyboard is shown.

+ (void)updateKeyboardBackground {
    UIView *peripheralHostView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] lastObject];

    UIView *backdropView;
    CustomKeyboard *customKeyboard;

    if ([peripheralHostView isKindOfClass:NSClassFromString(@"UIPeripheralHostView")]) {
        for (UIView *view in [peripheralHostView subviews]) {
            if ([view isKindOfClass:[CustomKeyboard class]]) {
                customKeyboard = (CustomKeyboard *)view;
            } else if ([view isKindOfClass:NSClassFromString(@"UIKBInputBackdropView")]) {
                backdropView = view;
            }
        }
    }

    if (customKeyboard && backdropView) {
        [[backdropView layer] setOpacity:0];
    } else if (backdropView) {
        [[backdropView layer] setOpacity:1];
    }
}

+ (void)keyboardWillShow {
    [self performSelector:@selector(updateKeyboardBackground) withObject:nil afterDelay:0];
}

+ (void)load {
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}

这篇关于iOS 7上的UITextView的inputView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆