返回viewController方向。迅速

时间:2019-11-26 16:28:13

标签: ios swift iphone uinavigationcontroller orientation

在应用程序中,我只有纵向方向。 但是一个视图具有横向。

问题在于它们都由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")

    }
}

1 个答案:

答案 0 :(得分:0)

我使用以下方法自己决定了一切

override func viewWillDisappear(_ animated: Bool) {
        appDel.myOrientation = .portrait
        UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")

    }