返回viewController方向。斯威夫特

问题描述 投票:0回答:1

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

问题是它们都由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
1个回答
0
投票

我使用以下方法自行决定了所有内容

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

    }
© www.soinside.com 2019 - 2024. All rights reserved.