iPhone/iPad 键盘调光

发布于 2024-12-23 22:11:43 字数 183 浏览 7 评论 0原文

我正在编写一个主要在晚上使用的通用应用程序。我需要显示键盘,但不希望键盘的浅色使用户失明和/或破坏他们的夜视能力。我不想经历创建自定义键盘的麻烦,所以我认为解决方案可能是在键盘上放置一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美男兮 2024-12-30 22:11:44

键盘作为新窗口的子视图被发现,该新窗口出现时会添加。发现它有点老套和脆弱(需要检查新的 iOS 版本,因为它之前已经改变)但它确实有效并且是允许的(我正是在应用程序商店中的应用程序中为夜间模式执行此操作) 。

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; // This assumes you aren't adding any new windows yourself

for(UIView *keyboard in tempWindow.subviews) 
{
    if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) // This was different in an earlier version of iOS, and may well change again in the future!
    {
        [keyboard addSubview:maskView];
        break;
    }
}

这是在响应 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).

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; // This assumes you aren't adding any new windows yourself

for(UIView *keyboard in tempWindow.subviews) 
{
    if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) // This was different in an earlier version of iOS, and may well change again in the future!
    {
        [keyboard addSubview:maskView];
        break;
    }
}

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.

卸妝后依然美 2024-12-30 22:11:44

尝试对 UITextFiled/UITextArea(正在使用的)的 inputView 属性应用所需的更改。

try applying the required changes on inputView property of UITextFiled/UITextArea (the one being used).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文