ios - 返回 viewController 方向。迅速
问题描述
在应用程序中,我只有纵向。但是一种视图是横向的。
问题是它们都由 NavigationController 连接。当我从视图返回时,从横向到纵向的方向没有改变。
如何修复 NavigationController 的关闭方法?
AppDelegate.swift
var orientationLock = UIInterfaceOrientationMask.portrait
var myOrientation: UIInterfaceOrientationMask = .portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return myOrientation
}
景观视图.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")
}
}
解决方案
我使用以下方法为自己决定了一切
override func viewWillDisappear(_ animated: Bool) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
推荐阅读
- here-api - HereMaps 定价中的“每月资产”是什么意思?
- python - 如何在 HTML 中获取文件的完整路径位置
- gradle - 从自定义插件动态加载 Gradle 插件
- javascript - PSPDFKIT instance.addEventListener('annotations.create') 缺少注释类型
- typescript - 强类型工作者
- excel - 如何复制vba单元格
- windows - 无法在本地 Windows gitlab runner 中执行 bash 脚本
- mapstruct - 我可以强制 mapstruct 将映射方法委托给另一个映射方法或默认(内置)转换吗?
- javascript - 将选中复选框的值获取到Javascript?
- python - 为什么下载5张图片后这个程序没有失败