【问题标题】:UIInputView background is invisible while keyboard is animating键盘动画时 UIInputView 背景不可见
【发布时间】:2014-01-29 02:56:35
【问题描述】:

我有一个带有UIInputView 输入附件视图的文本字段。

当我点击我的文本字段时,键盘飞入视图,我可以看到辅助视图的子视图,但它没有可见的背景。 键盘动画完成后,UIInputView 的背景就会弹出。

当键盘动画仍在播放时,我可以做些什么来强制 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];

【问题讨论】:

  • 也想在这里看到答案。这真是令人不安。

标签: objective-c ios7 uitextfield inputaccessoryview


【解决方案1】:

不是一个完整的解决方案,但如果您在 -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];

附:而且我知道,以这种愚蠢的方式定义颜色并不是一个完美的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多