xcode 如何在 SwiftUI 中以横向模式预览设备?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/56625931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I preview a device in landscape mode in SwiftUI?
提问by Felipe Pe?a
How can I preview a device in landscape mode in SwiftUI?
如何在 SwiftUI 中以横向模式预览设备?
I just have a simple preview like this:
我只有这样一个简单的预览:
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
回答by Mojtaba Hosseini
You can't rotate the devicein preview (yet), but you can set the size to any landscape size you want for PreviewProvider
:
您无法在预览中旋转设备(还),但您可以将尺寸设置为您想要的任何横向尺寸PreviewProvider
:
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
.previewLayout(.fixed(width: 568, height: 320)) // iPhone SE landscape size
}
}
This is iPhone SE
landscape mode size.
这是iPhone SE
横向模式大小。
Note: Since the size is completely custom, Xcode can not infer a device associated to it and will not apply the safe area as you expected for some iPads and iPhones landscape mode.
注意:由于大小是完全自定义的,Xcode 无法推断与其关联的设备,并且不会像您预期的那样为某些 iPad 和 iPhone 横向模式应用安全区域。
回答by C Williams
ContentView().previewLayout(PreviewLayout.fixed(width:568,height:320))