简体   繁体   English

iPad SwiftUI 仅横向

[英]iPad SwiftUI landscape orientation only

I've created a swiftUI app and noticed that no matter what settings I change, the iPad version of the app will always allow portrait orientation.我创建了一个 swiftUI 应用程序并注意到无论我更改什么设置,应用程序的 iPad 版本将始终允许纵向。 The iPhone version of the app works as expected.该应用程序的 iPhone 版本按预期工作。

Here are some screenshots of my settings:以下是我的一些设置截图:

在此处输入图像描述

在此处输入图像描述

How can I get the iPad app to only allow landscape orientation in SwiftUI?我怎样才能让 iPad 应用程序只允许 SwiftUI 中的横向方向? I am running Xcode 12.4我正在运行 Xcode 12.4

Unfortunately this does not seem to be supported with the SwiftUI application lifecycle, even with use of UIApplicationDelegateAdaptor.不幸的是,SwiftUI 应用程序生命周期似乎不支持这一点,即使使用 UIApplicationDelegateAdaptor 也是如此。 This may be an intentional design decision to encourage developers to design resizable window applications (for multitasking & macOS).这可能是一个有意的设计决策,以鼓励开发人员设计可调整大小的 window 应用程序(用于多任务和 macOS)。

If you switch to the UIKit lifecycle by replacing your App struct with UIApplicationDelegate/UISceneDelegate, you'll be able to allow only landscape orientation.如果您通过将 App 结构替换为 UIApplicationDelegate/UISceneDelegate 来切换到 UIKit 生命周期,则您将只能允许横向。

Yes you can change SwiftUI app landscape orientation only是的,您只能更改 SwiftUI 应用横向方向

  • Select iPad and deselect iPhone Select iPad 并取消选择 iPhone
  • Set the orientations support as required根据需要设置方向支持
  • Un-set Supports multiple windows if you want如果需要,未设置支持多个 windows
  • Switch back to iPhone and iPad切换回 iPhone 和 iPad

Here is the video demo这是视频演示视频演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM