ios - UIKeyboard 在 iOS7 中不会自动半透明

标签 ios objective-c ios7 xcode5 uikeyboard

我了解到,在使用 Xcode 5 和 iOS 7 项目进行开发时,与 UITextField 交互时弹出的键盘应该是半透明的,并且可以透过背景中的任何颜色显示。我的两个项目都不是这种情况。我有一个彩色和模糊的背景,我希望它能通过键盘显示出来;但是键盘仍然是默认的白色/灰色。

这是我到目前为止的演示:

UIColor *tintColor = [UIColor colorWithWhite:0.21 alpha:0.4];
UIColor *background = [[UIColor alloc] initWithPatternImage:[[UIImage imageNamed:@"universe.jpg"] applyBlurWithRadius:19
                                                                                                            tintColor:tintColor
                                                                                                saturationDeltaFactor:1.8
                                                                                                            maskImage:nil]];
self.view.backgroundColor = background;

UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(200, 200, 300, 60)];
[self.view addSubview:text];

我什至尝试将键盘外观类型设置为 UIKeyboardAppearanceDefault 和 UIKeyboardAppearanceLight

有人可以指导/告诉我如何实现键盘半透明效果吗?这应该是自动的吗? 谢谢

编辑 1:

我有 iPad mini、第三代 iPad 和第四代 iPad,均配备视网膜显示屏。 运行 iOS 7.0.2

最佳答案

您的代码、设置和示例在我的 xCode 上运行良好。我首先尝试只将背景颜色设置为明显的颜色,例如红色。

self.view.backgroundColor = [UIColor redColor];

这通过键盘显示。之后我尝试了一张没有模糊效果的图像。

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"images.jpeg"]];
img.frame = self.view.frame;
[self.view addSubview:img];

这可以显示出来,但没有红色那么明显,因为我使用的图像类似于您所说的星系,因此其中有很多黑色。

最后我尝试了您的确切代码,使用高斯模糊效果来创建颜色。

UIColor *tintColor = [UIColor colorWithWhite:0.21 alpha:0.4];
UIColor *background = [[UIColor alloc] initWithPatternImage:[[UIImage imageNamed:@"images.jpeg"] applyBlurWithRadius:19 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]];
self.view.backgroundColor = background;

这也有效,但很难注意到。深色被高斯模糊一次,然后被键盘再次模糊的综合影响使它几乎不被察觉。我建议您尝试类似的方法来查看您是否真的获得了透明键盘,因为如果您提供的代码和信息是正确的,那么您似乎是并且可能看不到它。

此外,键盘只是略微透明,因此如果您期望完全透明,则情况并非如此。这种轻微的透明度会被最小化,背景颜色越均匀,例如,如果您有全黑或全白背景,它就不会引人注意。

编辑:我确认在运行 iOS7.0.x 的 iPad 上情况并非如此 我得到标准的全灰色键盘,即使使用 Safari 等标准应用程序也是如此。 Apple 似乎没有针对如此大的屏幕优化透明度,这导致了延迟问题。这似乎也在 iOS7.1 中得到了部分修复,并且在 iOS7.1 中有更多透明的 iPad 功能,但人们建议关闭它们,因为它们会导致 iPad 运行速度比正常情况慢。

关于ios - UIKeyboard 在 iOS7 中不会自动半透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20793866/

相关文章:

iphone - Adobe Air 应用程序在 iOS7 上的 iPhone 5 上有黑条

jquery - iPhone iOS7 3D 选择/下拉功能

ios7 - iOS 7.1 上的 XLForm 空白

ios - 从字符串转换NSURL

ios - 强制 iOS 设备应用通过本地 WIFI 网络通话

iphone - iOS:从网址下载图片并保存在设备中

ios - 是什么使搜索栏选项所选择的Scope ButtonIndexDidChange执行?

ios - TableView 框架显示在意外位置

ios - Objective-C 问题 : Terminating app due to uncaught exception 'NSUnknownKeyException'

iphone - MPNowPlayingInfoCenter 与 AVAudioPlayer 兼容吗?