我有一个简单的问题,
为什么这完美无缺:
class HomeController: UIViewController,UITableViewDataSource,UITableViewDelegate, AddingDisciplineDelegate, LogoutUserDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let controller = SeePlugAlertModalView()
controller.modalPresentationStyle = .overFullScreen
self.present(controller, animated: true, completion: nil)
}
(...)
}
class SeePlugAlertModalView : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.isOpaque = false
self.modalTransitionStyle = .crossDissolve
view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
}
但是如果我将modalPresentationStyle放在SeePlugAlertView中,我的视图会显示但隐藏父视图控制器。 (即使背景颜色的alpha为0.5)。
class HomeController: UIViewController,UITableViewDataSource,UITableViewDelegate, AddingDisciplineDelegate, LogoutUserDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let controller = SeePlugAlertModalView()
self.present(controller, animated: true, completion: nil)
}
(...)
}
class SeePlugAlertModalView : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.isOpaque = false
self.modalPresentationStyle = .overFullScreen
self.modalTransitionStyle = .crossDissolve
view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
}
答案 0 :(得分:0)
问题是,在你的第二个代码中,当SeePlugAlertModalView的viewDidLoad
被调用时,它已经太晚了; SeePlugAlertModalView的呈现已经开始。因此,既然您已从HomeController中删除了早期配置,那么在演示时会有 no 设置演示文稿样式,并且您获得.fullScreen
(默认值)
解决方案是设置SeePlugAlertModalView的演示风格早期,例如在其初始化程序或awakeFromNib
中。