SwiftUI - Catalyst 半透明侧边栏

问题描述

目标是在 Mac Catalyst 上制作一个半透明的侧边栏

下面的代码提供了一个不透明的侧边栏(图 1)。

在 Mac(非催化剂)上,侧边栏看起来不错(图 2)。

是否可以在 Mac Catalyst 上提供半透明的侧边栏

enter image description here

enter image description here

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        NavigationView {
            
            //sidebar
            List {
                Label("Books",systemImage: "book.closed")
                Label("Tutorials",systemImage: "list.bullet.rectangle")
         
            }
            .background(Color.clear)

            .listStyle(SidebarListStyle())
            
            //content
            Text("Sidebar")
            .navigationTitle("Sidebar")
        }
        
        
    }
}

解决方法

从 AppDelegate main 开始,然后按照 Apple 的教程 re:UISplitViewController“将半透明背景应用到您的主视图控制器”。

https://developer.apple.com/documentation/uikit/mac_catalyst/optimizing_your_ipad_app_for_mac

将 UISplitViewController 包装在 UIViewControllerRepresentable 中时,我无法获得半透明效果,但确实获得了全高侧边栏。