UIInputView background is invisible while keyboard is animating

1.1k views Asked by At

I have a text field which has a UIInputView input accessory view.

When I tap my text field, and the keyboard comes flying into view and I can see the accessory view's subviews, but it has no visible background. Once the keyboard animation is complete, the UIInputView's background pops into view.

What can I do to force the UIInputView's background to be visible while the keyboard animation is still going?

Here's my code:

UIInputView *inputView = [[UIInputView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,                 CGRectGetWidth(self.bounds), 44.0f) inputViewStyle:UIInputViewStyleKeyboard];

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectInset(inputView.bounds, 15.0f, 2.0f);
[button setTitle:@"Button" forState:UIControlStateNormal];
[inputView addSubview:button];

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.bounds), 44.0f)];
textField.inputAccessoryView = inputView;
[self addSubview:textField];
1

There are 1 answers

0
Wisors On

Not a complete solution, but this impact can be minimized if you set background of your UIInputView manually inside -viewDidLoad: method. Fortunately, no need to remove it after. Right after appearing UIInputView will have a truly keyboard background and a blur effect as well.

UIColor *tmpBackground; //Keyboard have color base on the current device.
if ([UIDevice isPad] || (UIDevice isPod)]) { //These are my helpers, you have to implement it
   tmpBackground = [UIColor colorWithRed:207/255.0f green:210/255.0f blue:214/255.0f alpha:1];
} else {
   tmpBackground = [UIColor colorWithRed:216/255.0f green:219/255.0f blue:223/255.0f alpha:1];
}
[textField.inputAccessoryView setBackgroundColor:tmpBackground];

P.S. And I know, it is not a perfect solution to define colors in such a stupid way.