gpt4 book ai didi

ios - 在纵向状态下强制旋转 UIViewController

转载 作者:行者123 更新时间:2023-11-29 11:32:26 24 4
gpt4 key购买 nike

在这种环境下(在Project配置中修复支持方向为Portrait)

enter image description here

你能在 Landscape 中显示特定的 UIViewController 吗?

最佳答案

简短的回答是你不能,因为根据 Apple 文档 here

The system intersects the view controller's supported orientations with the app's supported orientations (as determined by the Info.plist file or the app delegate's application(_:supportedInterfaceOrientationsFor:) method) and the device's supported orientations to determine whether to rotate.

要实现您需要的功能,您还应该将允许的方向设置为横向,然后在您的 View Controller 中实现以下内容以允许纵向或横向(或两者):

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait//or UIInterfaceOrientationMask.landscape
}

然后要强制指定方向,您可以将方向设置为 UIDevice:

UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")

关于ios - 在纵向状态下强制旋转 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52176134/

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