3 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"]; [UINavigationController attemptRotationToDeviceOrientation];
let value = UIInterfaceOrientation.landscapeLeft.rawValueUIDevice.current.setValue(value, forKey: "orientation") UINavigationController.attemptRotationToDeviceOrientation()
- viewDidAppear:

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
UINavigationController
UITabBarController
給視圖控制器權(quán)力!
SWIFT 2.3
extension UINavigationController { public override func supportedInterfaceOrientations() -> Int { return visibleViewController.supportedInterfaceOrientations() } public override func shouldAutorotate() -> Bool { return visibleViewController.shouldAutorotate() }}extension UITabBarController { public override func supportedInterfaceOrientations() -> Int { if let selected = selectedViewController { return selected.supportedInterfaceOrientations() } return super.supportedInterfaceOrientations() } public override func shouldAutorotate() -> Bool { if let selected = selectedViewController { return selected.shouldAutorotate() } return super.shouldAutorotate() }}
SWIFT 3
extension UINavigationController { open override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return visibleViewController?.supportedInterfaceOrientations ?? super.supportedInterfaceOrientations } open override var shouldAutorotate: Bool { return visibleViewController?.shouldAutorotate ?? super.shouldAutorotate }}extension UITabBarController { open override var supportedInterfaceOrientations: UIInterfaceOrientationMask { if let selected = selectedViewController { return selected.supportedInterfaceOrientations } return super.supportedInterfaceOrientations } open override var shouldAutorotate: Bool { if let selected = selectedViewController { return selected.shouldAutorotate } return super.shouldAutorotate }}
supportedInterfaceOrientations
shouldAutoRotate
禁用旋轉(zhuǎn)
class ViewController: UIViewController { override func shouldAutorotate() -> Bool { return false }}
鎖定到特定方向
class ViewController: UIViewController { override func supportedInterfaceOrientations() -> Int { return Int(UIInterfaceOrientationMask.Landscape.rawValue) }}
- 3 回答
- 0 關(guān)注
- 644 瀏覽
添加回答
舉報(bào)