小编ray*_*nxw的帖子

SwiftUI iPad 是否支持演示定位器?

所以我的最低目标是 iOS 16,我使用 .sheet() 和 .presentationDetents([.medium]),它在 iOS (iPhone) 上运行良好。但当我在 iPadOS 上加载它时,它总是一张全尺寸的纸,似乎忽略了演示制动装置。这是演示此行为的最小可重现代码。

import SwiftUI

struct ContentView: View {
    @State var shouldShowSheet: Bool = false
    
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
            
            Button("Show Sheet") {
                shouldShowSheet.toggle()
            }
        }
        .padding()
        .sheet(isPresented: $shouldShowSheet, content: {
            VStack {
                Text("Some content")
                Text("Some more content")
                Text("Even more content")
                
                Button("Dismiss Sheet") {
                    shouldShowSheet.toggle()
                }
            }
            .presentationDetents([.medium])
        })
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
} …
Run Code Online (Sandbox Code Playgroud)

ipad swiftui swiftui-sheet

8
推荐指数
0
解决办法
1006
查看次数

标签 统计

ipad ×1

swiftui ×1

swiftui-sheet ×1