第一條:您可以訂閱系統通知有關設備旋轉這樣
NotificationCenter.default.addObserver(self, selector: #selector(self.orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
然後使功能
func orientationChanged() {}
對於正確的狀態判斷,我建議使用這種方法
UIApplication.shared.statusBarOrientation == .portrait
如果它的真實肖像,虛假景觀
因此,依賴於狀態,例如,您可以推一些vc在景觀和pop它當設備被轉回。 爲推動您可以輕鬆地創建視圖控制器的實例一樣,
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("here_is_vc_id") as! YourViewController
而對於流行:
_ = navigationController.pushViewController(vc, animated: true)
注意:VC你實例必須是儲存在一個(主)故事板。您還需要在「Storyboard ID」字段中的Identity Inspector中設置is(字符串「here_is_vc_id」)。
在這裏你去:)