iOS只旋转某一个页面
只旋转某一个页面
下面的代码只支持 self.present(vc, animated: true, completion: nil) 展现的页面,才可以旋转
在 UINavigationController 中重写下面方法
override var shouldAutorotate: Bool{ return self.topViewController?.shouldAutorotate ?? false } override var supportedInterfaceOrientations: UIInterfaceOrientationMask{ return self.topViewController?.supportedInterfaceOrientations ?? .portrait } override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{ return self.topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait }
在 UITabBarController 中重写下面方法
override var shouldAutorotate: Bool{ return self.selectedViewController?.shouldAutorotate ?? false } override var supportedInterfaceOrientations: UIInterfaceOrientationMask{ return self.selectedViewController?.supportedInterfaceOrientations ?? .portrait } override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{ return self.selectedViewController?.preferredInterfaceOrientationForPresentation ?? .portrait }
然后在需要旋转的页面中加入下面代码
override var shouldAutorotate: Bool{ return true } override var supportedInterfaceOrientations: UIInterfaceOrientationMask{ return UIInterfaceOrientationMask.landscapeRight } override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{ return .landscapeRight }

浙公网安备 33010602011771号