我正在尝试使用SwiftUI在另一个按钮内插入一个按钮。然而,如果我按下该按钮,它也会动画显示外部按钮被按下,即使它不运行操作闭包。是否有一种方法可以防止这种情况,例如使用自定义ButtonStyle?
它看起来像这样:
当内部按钮被按下时,它看起来像这样:
以下是我的代码:
var body: some View {
Button(action: {
print("outer button pressed")
}) {
HStack {
Text("Button")
Spacer()
Button(action: {
print("inner button pressed")
}) {
Circle()
.foregroundColor(Color.accentColor.opacity(0.2))
.frame(width: 28.0, height: 28.0)
.overlay(Image(systemName: "ellipsis"))
}
}
.padding()
.accentColor(.white)
.background(Color.accentColor)
.clipShape(RoundedRectangle(cornerRadius: 14.0, style: .continuous))
}
.frame(maxWidth: 200.0)
.padding()
}