如何在 iOS 中将相机视图方向锁定为横向?
How can I lock camera view orientation to landscape in iOS?
我想在横向模式下修复我的相机视图。并且还会在用户将视图旋转为纵向时显示警报。有什么解决办法吗?
将其放入您的视图控制器中:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape {
print("will turn to landscape")
} else {
print("will turn to portrait")
//print an alert box here
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
}
来源:How to detect orientation change?
或者把这个放到需要横屏的视图中:
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscape
}
但是这个不能 post 警报。
我想在横向模式下修复我的相机视图。并且还会在用户将视图旋转为纵向时显示警报。有什么解决办法吗?
将其放入您的视图控制器中:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape {
print("will turn to landscape")
} else {
print("will turn to portrait")
//print an alert box here
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
}
来源:How to detect orientation change?
或者把这个放到需要横屏的视图中:
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscape
}
但是这个不能 post 警报。