简体   繁体   中英

how to cancel OnDrag in swiftui?

I am making drag & drop lazyVGrid.

i did reference this answer

SwiftUI | Using onDrag and onDrop to reorder Items within one single LazyGrid?

when drag move another item position it working well

but when I long press and not move and drop itself self.dragging not set to nil

how can I fix it??

I would try to do like this.

.gesture(DragGesture()
    .onChanged({ value in
                    if value.x == 0 && value.y == 0 {
                        self.dragging = nil
                    }
                    })
)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM