【发布时间】:2021-02-07 04:16:25
【问题描述】:
我正在以编程方式创建一个没有情节提要的视图控制器。该应用仅支持“纵向设备方向(在项目常规设置中检查)”。
当应用程序以纵向启动时,它有一个正确的边界(0.0, 0.0, 375.0, 667.0);但是,当应用程序在 iPad 上以横向启动时,边界会更改为 (0.0, 0.0, 667.0, 375.0) 并以编程方式倾斜自动布局约束设置。
从下面的截图可以看出,导航栏中的标题不再居中,视图内的所有内容也是如此。
func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
print(">>>", windowScene.coordinateSpace.bounds)
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = MyViewController()
window?.makeKeyAndVisible()
}
【问题讨论】:
-
尝试约束布局
-
你的意思是设置
NSLayoutConstraint?你能详细说明你的评论吗?
标签: ios swift ipad autolayout uikit