gpt4 book ai didi

SwiftUI 表在 macOS Big Sur 上没有动画解雇

转载 作者:行者123 更新时间:2023-12-03 14:46:39 25 4
gpt4 key购买 nike

我希望表格解雇就像外观一样动画但相反。我认为这也是标准行为。例如,当您创建新文件时,您可以在 Xcode 中看到它。
但正如你所看到的,它在没有动画的情况下消失了
Demo
这是我的代码:

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()
}
}
我上线了
  • Mac mini (M1, 2020)
  • macOS Big Sur 11.1 (20C69)
  • Xcode 12.3 (12C33)

  • 但我可以在一个
  • Mac mini (2018)
  • macOS Big Sur 11.0.1 (20B29)
  • Xcode 12.2 (12B45b)
  • 最佳答案

    我终于想出了怎么做,在我的 SwiftUI 应用程序中,如果我在关闭工作表时执行此操作,它会起作用:

    isSheetVisible = false
    NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
    例子:
    struct SheetView: View {
    @Binding var isSheetVisible: Bool

    var body: some View {
    Button("Close") {
    isSheetVisible = false
    NSApp.mainWindow?.endSheet(NSApp.keyWindow!)
    }
    }
    }
    Working

    关于SwiftUI 表在 macOS Big Sur 上没有动画解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65390267/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com