我使用了磁力计,但它的值总是不同的。我想检测用户设备何时在横向位置处于水平平均值,并且在特定发布时想要执行某些操作。
In AppDelegate.swift inside the didFinishLaunchingWithOptions function put the below code :
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
then inside the AppDelegate put the following function:
func rotated() {
if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
print("Landscape")
}
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
print("Portrait")
}
}
hope it will work for you ... :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.