Luk*_*ger 11 swift swiftui macos-big-sur
我希望表格解雇就像外观一样动画但相反。我认为这也是标准行为。例如,当您创建新文件时,您可以在 Xcode 中看到它。
但正如你所看到的,它在没有动画的情况下消失了
这是我的代码:
struct ContentView: View {
@State var isAnotherViewPresented: Bool = false
var body: some View {
HStack {
Button(action: {
isAnotherViewPresented.toggle()
}, label: {
Text("Button")
}).sheet(isPresented: $isAnotherViewPresented, content: {
AnotherView()
})
}
.frame(width: 500, height: 300, alignment: .center)
}
}
struct AnotherView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
VStack {
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Close")
})
}.padding()
}
}
Run Code Online (Sandbox Code Playgroud)
我上线了
但我可以在一个
我终于想出了如何做到这一点,在我的 SwiftUI 应用程序中,如果我在关闭工作表时执行此操作,它就会起作用:
isSheetVisible = false
NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
Run Code Online (Sandbox Code Playgroud)
例子:
struct SheetView: View {
@Binding var isSheetVisible: Bool
var body: some View {
Button("Close") {
isSheetVisible = false
NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
815 次 |
| 最近记录: |