我使用的是Swift,我希望能够在旋转到横向时加载UIViewController,有人可以指出正确的方向吗?
我在网上找不到任何东西,并且对文档有些困惑。
这是我的工作方式:
在AppDelegate.swift
里面didFinishLaunchingWithOptions
我把函数:
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
然后在AppDelegate类中放入以下函数:
func rotated() {
if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
print("Landscape")
}
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
print("Portrait")
}
}
希望这对其他人有帮助!
谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句