我正在开发 iOS 应用程序。我有一个主视图,在这个 View 中 我正在尝试呈现一个背景变暗(黑色不透明)的模态视图 Controller 。 问题是状态栏不受此颜色影响并保持不变。
这就是我呈现 View Controller 的方式:
let shareViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ShareViewController") as! ShareViewController
shareViewController.battle = battle
shareViewController.delegate = self
let animation = CATransition()
animation.duration = 1
animation.type = kCATransitionFade
self.view.window?.layer.addAnimation(animation, forKey: kCATransition)
presentViewController(shareViewController, animated: false) {
() in
// nothing here
}
以下是演示问题的一些屏幕截图:
这就是问题所在(状态栏颜色): Problem illustration 这是 Storyboard 中的模态视图: storyboard
最佳答案
我无法重现您的问题,以下代码在我的单 View 应用中没有问题:
let viewController = UIViewController()
viewController.modalPresentationStyle = .overFullScreen
viewController.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
let animation = CATransition()
animation.duration = 1
animation.type = kCATransitionFade
self.view.window?.layer.add(animation, forKey: kCATransition)
self.present(viewController, animated: false, completion: nil)
但是请注意,您应该在 View 的根 Controller 上呈现。有时,当您从内部 Controller 进行演示时,您会得到奇怪的效果:
self.view.window?.rootViewController?.present(viewController, animated: false, completion: nil)
还要确保您使用的是正确的 modalPresentationStyle
。
关于ios - 模态视图 Controller 不覆盖状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35491746/