[英]How can i detect device orientation even if the orientation is locked
我使用了磁力計,但它的值總是不同的。我想檢測用戶設備何時在橫向位置處於水平平均值,並且在特定發布時想要執行某些操作。
在 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")
}
}
希望它對你有用... :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.