【发布时间】:2020-03-22 03:14:31
【问题描述】:
在应用程序中,我只有纵向。 但有一个视图是横向的。
问题是它们都由 NavigationController 连接。当我从视图返回时,从横向到纵向的方向没有改变。
如何修复 NavigationController 的关闭方法?
AppDelegate.swift
var orientationLock = UIInterfaceOrientationMask.portrait
var myOrientation: UIInterfaceOrientationMask = .portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return myOrientation
}
landscapeView.sift
import UIKit
class SchemeView: UIViewController {
let appDel = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
appDel.myOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
//does not work
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
}
【问题讨论】:
标签: ios swift iphone uinavigationcontroller orientation