Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIInputView background is invisible while keyboard is animating

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];
like image 355
Pim Avatar asked Jan 10 '14 08:01

Pim


1 Answers

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.

like image 182
Wisors Avatar answered Oct 09 '22 11:10

Wisors