iPhone/iPad 键盘调光
我正在编写一个主要在晚上使用的通用应用程序。我需要显示键盘,但不希望键盘的浅色使用户失明和/或破坏他们的夜视能力。我不想经历创建自定义键盘的麻烦,所以我认为解决方案可能是在键盘上放置一个 UIView 并给它一个 alpha 为 0.5 或其他值的黑色背景颜色,但是,我无法想象弄清楚如何让 UIView 覆盖键盘。有谁知道该怎么做?苹果允许这样做吗?
I am writing a universal app that will be used primarily at night. I will need to display a keyboard but do not want the light colors of the keyboard to blind the user and/or spoil their night vision. I do not want to have to go through the trouble to creating a custom keyboard so I thought a solution might be to place a UIView over the keyboard and give it a black background color with an alpha of 0.5 or something however, I can not figure out how to get a UIView to cover the keyboard. Does anyone know how to do this? Does Apple allow this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
键盘作为新窗口的子视图被发现,该新窗口出现时会添加。发现它有点老套和脆弱(需要检查新的 iOS 版本,因为它之前已经改变)但它确实有效并且是允许的(我正是在应用程序商店中的应用程序中为夜间模式执行此操作) 。
这是在响应
UIKeyboardDidShowNotification
对象的方法内完成的。我还没有在 iPad 上尝试过,这只是 iPhone 代码。正如您所说,蒙版视图只是一个带有黑色背景和一定透明度的普通视图。您还可以使用警报键盘样式,在按键之间留出一个黑色空间。
不幸的是,这种方法并不能阻止小按键闪烁(当您点击按键时弹出的较大按键)处于全亮度。
The keyboard is found as a subview of a new window that is added when it appears. Finding it is a little hacky and fragile (will need checking at new iOS versions, as it has changed before) but it does work and it is allowed (I do exactly this for a night mode in an app that is on the app store).
This is done inside the method that responds to the
UIKeyboardDidShowNotification
object. I've not tried it on the iPad, this is iPhone code only.The mask view is, as you say, just a plain view with a black background and some transparency. You can also use the alert keyboard style which gives a black space in between the keys.
This method does not prevent the little key flashes (the larger keys that pop up when you tap a key) from being at full brightness, unfortunately.
尝试对 UITextFiled/UITextArea(正在使用的)的
inputView
属性应用所需的更改。try applying the required changes on
inputView
property of UITextFiled/UITextArea (the one being used).