objective-c - UIInputView 背景在键盘动画时不可见

标签 objective-c ios7 uitextfield inputaccessoryview

我有一个文本字段,它有一个 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/

相关文章:

objective-c - Iphone:在单独的文件中编写一些方法以便从任何地方访问

ios - UIPageControl 不遵守它在 UIScrollView 中的约束

core-data - 从 iCloud 中删除核心数据存储

iphone - 加载数据uitextfield

ios - 当以编程方式将 UITextField 设置为 FirstResponder 时,会导致一些奇怪的文本编辑操作

objective-c - 从 UIImageVIew 获取 UIImage origin.x

objective-c - 使用 BOM 创建一个 UTF-8 字符串

iphone - iOS 读取多个子目录

ios - 我希望从 iPhone 浏览的用户可以选择只上传视频或图像,而不是同时上传

ios - 在viewDidLoad中使用BecomeFirstResponder是否正确