【发布时间】:2019-12-31 01:39:23
【问题描述】:
我在使用 SwiftUI ContextMenu 时遇到了一个奇怪的问题,很可能是一个错误,但也许其他人已经找到了解决方法。我将其简化为:
struct ContentView: View {
@State var number = 20
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
var body: some View {
Text("\(number)")
.padding()
.background(Color.green)
.contextMenu {
Button(action: {}) {
Image(systemName: "star")
Text("Test")
}
}
.onReceive(timer) { _ in
if self.number > 0 {
self.number -= 1
}
}
}
}
第一次出现 contextMenu 时,会显示正确的数字。 但是第二次出现contextMenu时,还是显示了contextMenu的第一个值。
【问题讨论】:
标签: swift contextmenu swiftui