以下是我是如何让它工作的:
在didFinishLaunchingWithOptions
函数的AppDelegate.swift
中,我放了:
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")
}
}
希望这对其他人有帮助!
谢谢