Loadex
Loadex

Reputation: 1512

Begin drag and drop after long tap

I'm creating a view where its subviews can be re-arranged with drag and drop, after activating the "edition mode" via a long tap.

I use for that two gesture reconizer a UILongPressGestureRecognizer and a UIPanGestureRecognizer.

Everything works great, but i wanna be able to start dragging my subviews without having to tap again on my view (like when you re-arrange your icon on the springboard).

Is there any way to do such a thing ?

EDIT :

I've tried :

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    var res = false

    if ((gestureRecognizer == longTapGesture && otherGestureRecognizer == panGesture) || (gestureRecognizer == panGesture && otherGestureRecognizer == panGesture)) {
        res = true
        println("🐷")
    }
    return true
}

without success.

Upvotes: 2

Views: 1046

Answers (1)

dadalar
dadalar

Reputation: 644

First of all those 2 gesture recognizers should work nicely together. Normally one of them would cancel the other one. To prevent that you can use UIGestureRecognizerDelegate method gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer: and return YES for both recognizers.

After that you need to have a boolean property to lock your pan effect before long press occurs. UILongPressGestureRecognizer target method should only perform something if this property is set to YES. Remember to set this property to NO, when pan gesture finishes/resets.

Upvotes: 1

Related Questions