我希望工作表解雇动画就像外观一样,但相反。我想这也是标准行为。例如,当您创建新文件时,您可以在 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()
}
}
I'm on
- Mac mini(M1,2020)
- macOS 大苏尔 11.1 (20C69)
- Xcode 12.3 (12C33)
但我可以在
- Mac 迷你 (2018)
- macOS 大苏尔 11.0.1 (20B29)
- Xcode 12.2 (12B45b)
我终于想出了如何做到这一点,在我的 SwiftUI 应用程序中,如果我在关闭工作表时执行此操作,它就会起作用:
isSheetVisible = false
NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
Example:
struct SheetView: View {
@Binding var isSheetVisible: Bool
var body: some View {
Button("Close") {
isSheetVisible = false
NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)