[英]SwiftUI contextMenu only in dark mode
Does anyone know why the contextMenu will only appear in dark mode when you put it in the view of a button:有谁知道为什么当您将 contextMenu 放在按钮视图中时,它只会以暗模式出现:
struct ContentView: View {
var body: some View {
Button(action: {
}) {
Text("Button with context menu")
.contextMenu {
Text("Menu Item")
}
}
}
}
Tried this on iOS and iPadOS, in the simulator and on device with os versions 14.4.1, 14.4.2 & 14.5.1.在 iOS 和 iPadOS、模拟器和操作系统版本为 14.4.1、14.4.2 和 14.5.1 的设备上进行了尝试。 I'm also almost sure, that this wasn't always the case.
我也几乎可以肯定,情况并非总是如此。
Probably a bug as @jnpdx said .可能是@jnpdx 所说的错误。 However, if you put the
contextMenu
outside the Button, it works fine.但是,如果将
contextMenu
放在 Button 之外,它就可以正常工作。
struct ContentView: View {
var body: some View {
Button(action: {
print("Button pressed")
}) {
Text("Button with context menu")
}
/// outside
.contextMenu {
Button(action: {
print("Menu button pressed")
}) {
Text("Menu Item")
}
}
}
}
Result:结果:
This Bug is fixed in iOS 16 Beta (20A5283p)此错误已在 iOS 16 Beta (20A5283p) 中修复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.