0

i am having some very strange issue. Basically i am implementing a drag and drop view with a snap to the horizontal 1D grid. Well, so when i drag a view and its center coordinate X is bigger or smaller then a different view, the non-dragged view should be animated to the left or right of its original position.

This works fine most of the time. But in some special cases its not working. In some situations specific situations the view does not receive any gesture callbacks anymore. I can reproduce this issue and have found out that when i remove the code that applies the animation, everything its working fine.

Basically this is the code that is called when the dragged view is at a position where the view below should be moved to the left or right

/**
 * Animate element to its saved position
 */
- (void)switchElement:(unsigned int)draggedIndex with:(unsigned int)otherIndex
{       
    // first animate
    UIView *view      = views[draggedIndex];
    UIView *otherView = views[otherIndex];
    // IF I COMMENT THIS OUT, EVERYTHING WORKS FINE 
    otherView.frame = [self getImageRectForIndex:draggedIndex];
    // now switch internally
    if(draggedIndex != otherIndex)
    {
        // switch views 
        views[draggedIndex]      = otherView;
        views[otherIndex] = view;
    }
}

Any idea if there is something to have in mind if i animate UIViews and have gesture recognizers attached to them?

If somebody is willing, i can paste the whole class here to test it.

SOLUTION I am having some "highlight" views in my design. And i have moved the relevant views behind those transparent background views by accident. So now i am not using addSubview: but insertSubview:atIndex: instead.

But marking @Anthonin C. answers as the right one. Because it pointed me in the correct direction (I found it out by overriding the hitTest: method)

Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
  • Is your animation blocking the user interaction? Do a search for UIViewAnimationOptionAllowUserInteraction, it might help you out. e.g. http://stackoverflow.com/questions/5181216/user-interaction-with-uiview-and-animation-completion-blocks – Dominic Jun 16 '16 at 15:06
  • well, i simplified the code. its not connected to the animation. Because setting the frame directly also seems to block all gesture callbacks – Martin Mlostek Jun 16 '16 at 15:08
  • i have created a repo with a simple example – Martin Mlostek Jun 16 '16 at 16:43

1 Answers1

1

Would you please track the otherView.bounds property to verify that your touch isn't out of bounds. I faced this issue recently and Apple documentation provide solution here : Delivering touch events to a view outside the bounds of its parent view

Sorry, I don't have enough reputation to comment your answer.

AnthoPak
  • 4,191
  • 3
  • 23
  • 41