主要是函数的官方意义、别的没用
viewController 中写
1、override var shouldAutorotate: Bool {
return true /// 代表允许屏幕旋转 false是进来后无法动啦
}
2、override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
/// .pro... 是进来后就一个方向不用考虑3,而.landscape存在着两个方向需要用3来指定一下刚进来时的方向
return .landscape
}
3、override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
/// 指定一下刚进来时的方向 这个时候1返回true、2返回 .landscape ,就能实现屏幕180度旋转效果了😁
return .landscapeLeft
}
模态未做考虑&&配置未述💭
首先 若有 navigationController 设为root viewcontroller 并添加
import Foundation
/// NavigationController中写
class WKNavigationController: UINavigationController {
override var shouldAutorotate : Bool {
return self.viewControllers.last!.shouldAutorotate
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return self.viewControllers.last!.supportedInterfaceOrientations
}
override var preferredInterfaceOrientationForPresentation : UIInterfaceOrientation {
return self.viewControllers.last!.preferredInterfaceOrientationForPresentation
}
override var prefersStatusBarHidden: Bool {
return self.viewControllers.last!.prefersStatusBarHidden
}
}