我想在横向模式下修复我的相机视图。并且当用户将视图旋转为纵向时也会显示警报。有什么解决方案吗?
答案 0 :(得分:0)
将它放在视图控制器中:
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
}
但是这个人不能发布警报。