UIDragInteraction on customView with UIButton

Hey,



I'm currently working on implementing dragging an custom view, which has a button spanned over it. Starting the drag works without any problem because this requires a long press on the view. Problems arise if I want to add another custom view to this drag session via tapping onto it. Tapping on the view will automatically trigger the UIControlEventTouchUpInside event of the button and thus, the dragInteraction:itemsForAddingToSession:withTouchAtPoint: will never be called. Is there any way to kinda give the UIDragAddItemsGesture a higher priority over the UIControlEventTouchUpInside of the button?

Replies

Why not set the userInteractionEnabled property of the button to false when drag session is active and then set to true when drag session ends.

Hey, thanks for your respone.
I didn't consider that as an option because I have many of those views and setting the userInteractionEnabled everytime a draginteraction is started/stopped would be pretty costly.

You could try experiementing with hitTest in your custom view and return the view you are interested in instead of the button.

Thanks, I will try that.


But the weird thing is that even if the button does not have any target assigned, the dragInteraction:itemsForAddingToSession:withTouchAtPoint: will still not be called when the button is tapped.