根据您的意见,您希望将所有屏幕保持为纵向,但如果知道设备是否处于横向而不旋转界面(对于相机屏幕),您应该
-
设置
支持的接口方向
在里面
your info.plist
-
使用检测设备方向
CMMotionManager
let motionManager = CMMotionManager()
var currentOrientation = UIDeviceOrientation.portrait
func montiorOrientation() {
motionManager.startAccelerometerUpdates(to: OperationQueue()) { data, error in
if let error = error {
print("CM orientation error - \(error)")
return
}
let acceleration = data!.acceleration
let orientation: UIDeviceOrientation = fabs(acceleration.y) < fabs(acceleration.x) ?
(acceleration.x > 0 ? .landscapeRight : .landscapeLeft) :
(acceleration.y > 0 ? self.currentOrientation : .portrait) // Ignore portraitUpsideDown
if orientation != self.currentOrientation {
DispatchQueue.main.async {
self.currentOrientation = orientation
}
}
}
}