简体   繁体   English

标签栏 iPad 应用到侧边栏 macOS Catalyst 应用

[英]Tabbar iPad App to Sidebar macOS Catalyst app

I am struggling to figure out how to turn my tabbar based iPad app into a sidebar navigation based Catalyst app.我正在努力弄清楚如何将基于标签栏的tabbar应用程序转变为基于侧边栏导航的Catalyst应用程序。 Similar to the screenshot that Apple shows:类似于 Apple 显示的屏幕截图:

在此处输入图像描述

You can see in the screenshot above the iPad app uses a tabbar layout but the macOS Catalyst app used a left sidebar navigation.您可以在上面的屏幕截图中看到tabbar应用程序使用标签栏布局,但macOS Catalyst 应用程序使用左侧边栏导航。

How can I do this and convert my iPad app to use a sidebar in macOS ?如何执行此操作并将我的 iPad 应用程序转换为在macOS中使用侧边栏?

You can do something like this你可以做这样的事情

#if targetEnvironment(macCatalyst)
    // here use the NavigationView + NavigationLinks to make the sidebar on macOS
#else
    // here use the Tab Bar view. 
#endif

You can use this to create entire alternate views if you need.如果需要,您可以使用它来创建整个备用视图。

For example:例如:

#if targetEnvironment(macCatalyst)
struct MyView: View {
    var body: some View {
        Text("Im in macOS")
    }
}
#else
struct MyView: View {
    var body: some View {
        Text("Im in iOS")
    }
}
#endif

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

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