我想以横屏模式修复相机视图。并且当用户将视图旋转到纵向时也显示警报。有没有可用的解决方案?
最佳答案
将其放在您的视图控制器中:
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
}
但这不能发布警报。
关于ios - 如何在iOS中将相机 View 方向锁定为横向?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42595444/