Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView's inputView on 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

like image 833
mim Avatar asked Sep 24 '13 14:09

mim


1 Answers

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];
}
like image 140
Jens Utbult Avatar answered Oct 13 '22 06:10

Jens Utbult