【发布时间】:2017-12-21 05:57:49
【问题描述】:
当用户点击非 UIViewController 类中的按钮时,我试图隐藏状态栏,但没有成功。
我正在使用以下代码来呈现UIAlertController:
public extension UIAlertController
{
func show()
{
let win = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
win.rootViewController = vc
win.windowLevel = UIWindowLevelAlert + 1
win.makeKeyAndVisible()
vc.present(self, animated: true, completion: nil)
}
}
jazzgil 引用了以下答案:
ios - present UIAlertController on top of everything regardless of the view hierarchy
在我的UIButton 操作中,我实现了以下内容:
@IBAction func setImage(_ sender: UIBarButtonItem)
{
let alertView = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
// Create the alert's action button
let okAction = UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
})
let cancelAction = UIAlertAction(title: "CANCEL", style: .destructive, handler: nil)
alertView.addAction(okAction)
alertView.addAction(cancelAction)
alertView.show()
}
我尝试在扩展中添加以下功能:
override open var prefersStatusBarHidden: Bool
{
return true
}
然后设置alertView.modalPresentationCapturesStatusBarAppearance = true 和alertView.setNeedsStatusBarAppearanceUpdate() 但状态栏似乎总是出现。
有人可以指导我正确的方向吗?
谢谢!
【问题讨论】:
标签: ios swift uialertcontroller