@State var longPressUsed = false
var body: some View {
var longPress: some Gesture {
LongPressGesture(minimumDuration: 2)
.updating($revealTip) { currentstate, gestureState, transaction in
(1) self.longPressUsed = true
}
.onEnded(finished in
(2) self.longPressUsed = true
}
}
}
How do I register long-press usages excluding repeated? Placing it in (1) leads to a warning that state variables should not be touched when the view is changing. When placed in (2), the code is not always called.
Use only .onEnded
, it is called when really long press is detected
var longPress: some Gesture {
LongPressGesture(minimumDuration: 2)
.onEnded { _ in
self.longPressUsed = true
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.