SwiftUI的 TapGesture
记录一下SwiftUI的 TapGesture的使用方法:
import SwiftUI
struct GestureBootCamp: View {
@State var isClick = false
var body: some View {
VStack{
Button(action: {
isClick.toggle()
}, label: {
/*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
.font(.headline)
.foregroundColor(.white)
.padding()
.padding(.horizontal, 50)
.background(.blue)
.cornerRadius(20)
})
Text("tap guesture")
.font(.headline)
.foregroundColor(.white)
.padding()
.padding(.horizontal, 50)
.background(.blue)
.cornerRadius(20)
// .onTapGesture {
// isClick.toggle()
// }
.onTapGesture(count: 2, perform: {
isClick.toggle()
})
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(isClick ? .red : .green)
}
}
#Preview {
GestureBootCamp()
}