在iOS 13中,模态视图控制器在呈现时有一个新的行为。
现在它不是全屏默认情况下,当我向下滑动时,应用会自动解除视图控制器。
我怎么能防止这种行为,并回到旧的全屏模态vc?
谢谢
在iOS 13中,模态视图控制器在呈现时有一个新的行为。
现在它不是全屏默认情况下,当我向下滑动时,应用会自动解除视图控制器。
我怎么能防止这种行为,并回到旧的全屏模态vc?
谢谢
当前回答
class MyViewController: UIViewController {
convenience init() {
self.init(nibName:nil, bundle:nil)
self.modalPresentationStyle = .fullScreen
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
而不是调用self。modalPresentationStyle = . fullscreen对于每个视图控制器,你可以子类化UIViewController并在任何地方使用MyViewController。
其他回答
设置导航控制器。modalPresentationStyle到。fullscreen已经重复了一千多次了,但让我给你们展示另一个阻止器,它会导致UIViewController / UINavigationController没有在全屏显示,即使所有的属性都设置正确。
对我来说,罪魁祸首就藏在这条线里
navigationController?.presentationController?.delegate = self
显然,当设置UIAdaptivePresentationControllerDelegate时,你需要在可选的delegate方法中指定表示样式
public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
presentationStyle
}
如果你有一个带有嵌入式导航控制器的UITabController,你必须将UITabController的显示设置为全屏,如下图所示
最初,modalPresentationStyle的默认值是全屏,但在iOS 13中,它的变化是UIModalPresentationStyle.automatic。
如果你想要创建全屏视图控制器,你必须将modalPresentationStyle更改为fullScreen。
参考UIModalPresentationStyle苹果文档了解更多细节,并参考苹果人机界面指南了解应该在哪里使用哪种模式。
let Obj = MtViewController()
Obj.modalPresentationStyle = .overFullScreen
self.present(Obj, animated: true, completion: nil)
//如果你想禁用滑动来消除它,添加行
Obj.isModalInPresentation = true
查看苹果文档获取更多信息。
class MyViewController: UIViewController {
convenience init() {
self.init(nibName:nil, bundle:nil)
self.modalPresentationStyle = .fullScreen
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
而不是调用self。modalPresentationStyle = . fullscreen对于每个视图控制器,你可以子类化UIViewController并在任何地方使用MyViewController。