
< /p>
До сих пор я пробовал что-то похожее на документацию Apple здесь:
https://developer.apple.com/documentati ... essgesture
Но похоже, что жест завершается, как только он достигает минимальной длительности, определенной в жесте. Я бы хотел, чтобы этот жест продолжался до тех пор, пока пользователь удерживает его, и прекращался, как только он его отпускает.
Кроме того, я не в теме, когда дело доходит до перетаскивания. и выберите другие кнопки. Вот мой подход на данный момент:
struct Example: View {
@GestureState var isDetectingLongPress = false
@State var completedLongPress = false
var longPress: some Gesture {
LongPressGesture(minimumDuration: 3)
.updating($isDetectingLongPress) { currentState, gestureState,
transaction in
gestureState = currentState
transaction.animation = Animation.easeIn(duration: 2.0)
}
.onEnded { finished in
self.completedLongPress = finished
}
}
var body: some View {
HStack {
Spacer()
ZStack {
// Three button array to fan out when main button is being held
Button(action: {
// ToDo
}) {
Image(systemName: "circle.fill")
.frame(width: 70, height: 70)
.foregroundColor(.red)
}
.offset(x: self.isDetectingLongPress ? -90 : 0, y: self.isDetectingLongPress ? -90 : 0)
Button(action: {
// ToDo
}) {
Image(systemName: "circle.fill")
.frame(width: 70, height: 70)
.foregroundColor(.green)
}
.offset(x: 0, y: self.isDetectingLongPress ? -120 : 0)
Button(action: {
// ToDo
}) {
Image(systemName: "circle.fill")
.frame(width: 70, height: 70)
.foregroundColor(.blue)
}
.offset(x: self.isDetectingLongPress ? 90 : 0, y: self.isDetectingLongPress ? -90 : 0)
// Main button
Image(systemName: "largecircle.fill.circle")
.gesture(longPress)
}
Spacer()
}
}
Подробнее здесь: https://stackoverflow.com/questions/673 ... ntext-menu
Мобильная версия