我有一个文本字段,它有一个 UIInputView输入附件 View 。
当我点击我的文本字段时,键盘飞入 View ,我可以看到附件 View 的 subview ,但它没有可见的背景。 一旦键盘动画完成,UIInputView 的背景就会弹出到 View 中。
我该怎么做才能在键盘动画仍在播放时强制显示 UIInputView 的背景?
这是我的代码:
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];
最佳答案
这不是一个完整的解决方案,但如果您在 -viewDidLoad:
方法中手动设置 UIInputView 的背景,则可以将这种影响降至最低。幸运的是,之后无需将其删除。出现后的 UIInputView 将具有真正的键盘背景和模糊效果。
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];
附言而且我知道,以这种愚蠢的方式定义颜色并不是一个完美的解决方案。
关于objective-c - UIInputView 背景在键盘动画时不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21039174/