gpt4 book ai didi

ios - 如何在 iOS 中将相机 View 方向锁定为横向?

转载 作者:行者123 更新时间:2023-11-30 12:38:17 26 4
gpt4 key购买 nike

我想修复横向模式下的相机 View 。当用户将 View 旋转为纵向时,还会显示警报。有什么解决办法吗?

最佳答案

将其放入 View Controller 中:

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.landscapeLe‌​ft.rawValue, forKey: "orientation")
}
}

来源:How to detect orientation change?

或者将其放入需要横向显示的 View 中:

override func shouldAutorotate() -> Bool {
return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscape
}

但是这个无法发布警报。

关于ios - 如何在 iOS 中将相机 View 方向锁定为横向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42595444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com