iPhone X 上的警报显示不同颜色的 UIAlertController 弹出窗口 [英] Alerts on iPhone X shows different color with UIAlertController popup

查看:26
本文介绍了iPhone X 上的警报显示不同颜色的 UIAlertController 弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初在 Xcode 8 中为 iOS 10 构建了一个应用程序.我最近升级到 Xcode 9 并且一直在修复我的 iPhone X 和 iOS 11 应用程序.我遇到的一个问题是如何制作整个屏幕(包括缺口区域)在显示警报时变暗.看图:

I have an app I built in Xcode 8 for iOS 10 originally. I recently upgraded to Xcode 9 and have been making fixes to my app for the iPhone X and iOS 11. One issue I'm having a lot of trouble with is how to make the whole screen (including the area by the notch) dim when presenting an alert. See image:

我正在连接"视图控制器(您在下面看到的内容)上显示警报.我没有做任何操作这个视图控制器的根视图.我已经检查"了这个根视图的故事板中的安全区域相对边距"和安全区域布局指南".(我也尝试过检查/不检查这些框的所有其他排列,但没有任何区别.)

I am presenting the alert on the "Connect" View Controller (what you see below). I've done nothing to manipulate the root View of this View Controller. I have "checked" "Safe Area Relative Margins" and "Safe Area Layout Guide" in the Storyboard for this root view. (I've also tried every other permutation of checking / not checking these boxes, and nothing makes a difference.)

有趣的是,当我在自己的 iPhone 6 上运行这个构建时,状态栏也没有变暗(虽然它不那么明显,因为状态栏在 iPhone X 之前要小得多).这个问题肯定是在 Xcode 9 中开始出现的,因为我在 App Store 上的当前版本(使用 Xcode 8 构建)在警报时使整个屏幕变暗.

Interestingly, when I run this build on my own iPhone 6, the status bar is also not dimmed (although it's a lot less noticeable since the status bar is a lot smaller pre-iPhone X). This issue definitely began occurring in Xcode 9 because my current version on the App Store (built with Xcode 8) dims the whole screen on alerts.

有没有人对如何解决这个问题有任何想法?如果您需要其他信息,请告诉我.

Does anyone have any ideas on how to solve this issue? Let me know if you need other information.

推荐答案

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

使用将子视图添加到 UIWindow 作为 -

Use adding subview to the UIWindow as -

UIApplication.shared.statusBarStyle = .lightContent//for white color
let statusBarBgView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIApplication.shared.statusBarFrame.height))

statusBarBgView.backgroundColor = UIColor.red//status bar color
window?.rootViewController = MYViewController//Entry point 
window?.rootViewController?.view.addSubview(statusBarBgView)//Adding to window

带有警报弹出窗口的结果 ->

后台应用列表结果 ->

这篇关于iPhone X 上的警报显示不同颜色的 UIAlertController 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆