I'm showing a Text View when a button with an image is long-pressed.
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var colorScheme
var isDark: Bool {
return colorScheme == .dark
}
@State private var showLabel = false
var body: some View {
Button(action: {
}) {
VStack {
ZStack {
Image(systemName: "swift")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 32)
.padding(.horizontal, 40)
.padding(.vertical, 6)
.background(.gray.opacity(0.2), in: RoundedRectangle(cornerRadius: 10))
.onTapGesture {
showLabel.toggle()
}
.onLongPressGesture(minimumDuration: 2) {
print("Long pressed...")
showLabel.toggle()
}
if showLabel {
Text("Help Content")
.font(.caption)
.foregroundStyle(!isDark ? .white : .black)
.padding(10)
.background(!isDark ? .black : .white, in: Rectangle())
.onTapGesture {
print("hey")
showLabel.toggle()
}
.offset(x: 120)
}
}
}
}
}
}
So a Text View will appear as shown in the image above. But its .onTapGesture is never called. I wonder why? Thanks.
Hi @Tomato ,
Have you tried using simultaneousGesture? This allows you to use two gestures at the same time.
Best,
Sydney