【发布时间】:2017-03-04 11:27:42
【问题描述】:
我想在横向模式下修复我的相机视图。并且当用户将视图旋转为纵向时也会显示警报。有什么解决办法吗?
【问题讨论】:
标签: ios swift camera orientation
我想在横向模式下修复我的相机视图。并且当用户将视图旋转为纵向时也会显示警报。有什么解决办法吗?
【问题讨论】:
标签: ios swift camera orientation
把它放在你的视图控制器中:
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
}
但是这个不能发布警报。
【讨论】: