UITextView inputView on iOS 7

I am trying to create a custom keyboard for UITextField, the background of this input must be transparent, I set the background color in the xib file to view in order to "clear the color". It works fine on iOS 6 and earlier .. but on iOS 7 it doesn’t work. Any idea how I can get it to work? I want it to be completely transparent.

+6
source share
3 answers

This will cause when you display your user keyboard and reset it to 1, when the normal keyboard is displayed, the opacity of the background images will be displayed.

+ (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]; } 
+5
source

I am pursuing the same problem because I have a numeric keypad that fills only the left half of the screen in landscape mode (and is mostly unsuitable for use on iOS7, where the blur effect covers the entire width of the screen). I did not quite understand how to get what I want (a blurred background is just behind my actual inputView), but I figured out how to completely disable the blur:

  • Define a custom subclass of UIView and specify what is in your xib file
  • In this class, override willMoveToSuperview: as follows

     - (void)willMoveToSuperview:(UIView *)newSuperview { if (UIDevice.currentDevice.systemVersion.floatValue >= 7 && newSuperview != nil) { CALayer *layer = newSuperview.layer; NSArray *subls = layer.sublayers; CALayer *blurLayer = [subls objectAtIndex:0]; [blurLayer setOpacity:0]; } } 

This apparently affects the background of every custom inputView that I have (but not on the system keyboard), so you may need to save / restore any value of normal opacity when your input view is removed from the supervisor if you don't want what.

0
source

iOS 7 does some things under the hood that are not documented. However, you can check the hierarchy of views and customize the corresponding views by overriding -willMoveToSuperview in your custom input view. For example, this code will make a transparent background:

 - (void)willMoveToSuperview:(UIView *)newSuperview { NSLog(@"will move to superview of class: %@ with sibling views: %@", [newSuperview class], newSuperview.subviews); if ([newSuperview isKindOfClass:NSClassFromString(@"UIPeripheralHostView")]) { UIView* aSiblingView; for (aSiblingView in newSuperview.subviews) { if ([aSiblingView isKindOfClass:NSClassFromString(@"UIKBInputBackdropView")]) { aSiblingView.alpha = 0.0; } } } } 
0
source

Source: https://habr.com/ru/post/954515/


All Articles