Questions tagged [swiftui-ontapgesture]
49 questions
11
votes
3 answers
SwiftUI TabView: how to detect click on a tab?
I would like to run a function each time a tab is tapped.
On the code below (by using onTapGesture) when I tap on a new tab, myFunction is called, but the tabview is not changed.
struct DetailView: View {
var model: MyModel
@State var…

Daniele B
- 19,801
- 29
- 115
- 173
5
votes
2 answers
SwiftUi sheet is blank on first tap but works correctly afterwards
I have a sheet that I put outside a foreach loop . When I click on Tapgesture the first time the results are blank, after the first time I get the correct data for every row I tap . I have read Sheet inside ForEach doesn't loop over items SwiftUI…

user1591668
- 2,591
- 5
- 41
- 84
2
votes
3 answers
How to have onTap gestures on Map and MapAnnotation both, without the two interferring with each other?
I have a SwiftUI Map with MapAnnotations.
I would like to have an onTap gesture on the Map, so it deselects the selected annotations, and dissmisses a bottom sheet, etc. Also would like to have an onTap gesture on the annotation item (or just having…

Gergely Kovacs
- 489
- 5
- 12
2
votes
1 answer
Why is Text onTapGesture not working for widened frame in SwiftUI?
I have this testing file that is not working how I expect it to.
import SwiftUI
struct SwiftUIView: View {
@State var boolTest = false
var nums = ["1","2","3","4","5","6","7"]
var body: some View {
VStack {
…

Tomas
- 135
- 1
- 6
2
votes
1 answer
How to detect a tap on a link and tap coordinates at the same time in SwiftUI?
In my SwiftUI app, some parts of text need to be tappable. On taps, some custom actions should occur, not necessarily opening a web page. At the same time I need to detect tap coordinates. I was going to use a drag gesture handler for that.
I…

Alexander Poleschuk
- 892
- 12
- 22
2
votes
1 answer
SwiftUI Tap Gesture Start / End Actions
I try to add action when a tap gesture start and end but its not work !!! and bellow the example code.
@State private var opacity = 1.0
var body: some View {
Image(systemName: "plus.square.on.square")
.opacity(opacity)
…

Ammar Ahmad
- 534
- 5
- 24
1
vote
0 answers
How to create a button in SwiftUI that, when tapped, automatically starts the call in one action (not using tel: hyperlink)?
Currently, I have created a button that, when tapped, launches a phone number as a hyperlink in SwiftUI:
Button(action: {
guard let phoneNum = URL(string: "tel://1-123-456-7890") else {return}
UIApplication.shared.open(phoneNum)
}) {
…

pulsetime
- 111
- 2
1
vote
1 answer
SwiftUI - Multiple views react simultaneously to gesture?
I am attempting to allow one tap gesture to trigger different views that are in a ZStack. When I tap on the red square that is superimposed on the yellow square, I would like both to react to the touch.
So if I tap on the red square, I should…

Pete
- 213
- 1
- 13
1
vote
2 answers
How do I make a image/icon’s opacity change on a tap gesture in SwiftUI
I have a heart image/system image that I want to appear by changing the opacity when you tap it two times, but I cannot figure out how to.
import SwiftUI
import PlaygroundSupport
struct ContentView: View{
var body: some View{
…

ciney
- 11
- 1
1
vote
1 answer
SwiftUI Buttons and their tappable areas shifted away and doesn't cover anymore
I have the problems with views and especially buttons as they can be tapped (but it applies to all views) that they tappable (focus area) shifted a bit from rendered views.
Layout stays ok but if you want to tap at the button its tappable area is…

Michał Ziobro
- 10,759
- 11
- 88
- 143
1
vote
1 answer
TapGesture and Button is not working in list if adding simultaneousGesture with minimumDistance: 0.0 - SwiftUI
I need to use a List for reusability that it provided and disable the scroll based on adding simultaneousGesture with DragGesture(minimumDistance: 0.0) to support iOS 15. scrollDisabled is only for iOS 16.
So when adding the gesture to the list…

Sajjad Sarkoobi
- 827
- 8
- 18
1
vote
2 answers
SwiftUI - modifiying variable foreach on View before onTapGesture()
Foreach on view must be presented with a View to process.
struct Home : View {
private var numberOfImages = 3
@State var isPresented : Bool = false
@State var currentImage : String = ""
var body: some View {
VStack {
TabView…

kelalaka
- 5,064
- 5
- 27
- 44
1
vote
1 answer
onTapGesure not registering for background of ScrollView
For some reason, the .onTapGesture event won't fire for the background of the ScrollView, but it does fire correctly when applied to the background of a nested VStack view:
var body: some View {
ScrollView {
VStack {...}
…

Jake Maschoff
- 15
- 4
1
vote
1 answer
What is the tappable area for onLongPressGesture?
I need to define the tap target for a component so I decide to have a simple example to experiment with. However, in this code below, the tapable area seem to be random to me i.e I can tap on the text hello, outside/inside of red border or…

oaranger
- 169
- 1
- 11
1
vote
1 answer
SwiftUI VStack cell onTap acting strange
I have a bunch of cells in a vertical scroll view, but am seeing some weird behavior from the onTapGesture and fullScreenCover for those cells. When I click on a cell, it registers the correct cell in onTapGesture but presents the wrong object, in…

Noah Iarrobino
- 1,435
- 1
- 10
- 31