Ios 在景观中呈现模态VC时,父VC的安全区域发生变化
当我演示第二个ViewController时,第一个UIViewController中的安全区域插入将更改为横向安全区域插入,后者仅支持横向 FirstViewController:Ios 在景观中呈现模态VC时,父VC的安全区域发生变化,ios,ios11,landscape,landscape-portrait,safearealayoutguide,Ios,Ios11,Landscape,Landscape Portrait,Safearealayoutguide,当我演示第二个ViewController时,第一个UIViewController中的安全区域插入将更改为横向安全区域插入,后者仅支持横向 FirstViewController: class ViewController: UIViewController { @IBAction func showSecondVC(_ sender: Any) { let storyboard = UIStoryboard(name: "Main", bundle: nil) le
class ViewController: UIViewController {
@IBAction func showSecondVC(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "SecondViewController")
self.present(controller, animated: true, completion: {
print("completed")
})
}
override func viewSafeAreaInsetsDidChange() {
print(view.safeAreaInsets)
super.viewSafeAreaInsetsDidChange()
print(view.safeAreaInsets)
}
}
class SecondViewController: UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.landscape]
}
@IBAction func dismissYourSelff(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
}
第二视图控制器:
class ViewController: UIViewController {
@IBAction func showSecondVC(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "SecondViewController")
self.present(controller, animated: true, completion: {
print("completed")
})
}
override func viewSafeAreaInsetsDidChange() {
print(view.safeAreaInsets)
super.viewSafeAreaInsetsDidChange()
print(view.safeAreaInsets)
}
}
class SecondViewController: UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.landscape]
}
@IBAction func dismissYourSelff(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
}
控制台输出:
UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0)
UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0)
UIEdgeInsets(top: 0.0, left: 44.0, bottom: 21.0, right: 44.0)
UIEdgeInsets(top: 0.0, left: 44.0, bottom: 21.0, right: 44.0)
completed
这就是我解决约束问题的方法: 我不得不使用快照来防止TabBar和TableView的错误布局
override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
var completionToRemoveSnapshot: (() -> ())? = nil
let shouldUseSnapshot = SDiOSVersion.deviceSize() == .Screen5Dot8inch &&
viewControllerToPresent.supportedInterfaceOrientations == .landscape
if shouldUseSnapshot {
if let snapShot = self.view.snapshotView(afterScreenUpdates: true) {
viewController.view.addSubview(snapShot)
completionToRemoveSnapshot = { snapShot.removeFromSuperview() }
}
}
super.present(viewControllerToPresent, animated: flag, completion: {
completionToRemoveSnapshot?()
completion?()
})
}
您找到解决方案了吗?@MrJre请在下面检查我的答案。我修复了它,在演示期间显示快照,然后将其删除。仅适用于iPhone X设备。