0

I have the following UI on an iPad app:

enter image description here

Here is an explanation of what's going on:

  1. Blue area is the View attached to the (displayed) ViewController.
  2. Yellow area is an UIImageView where users can drag items around (what I call the live area). Yellow is a subview of blue area.
  3. Red item is an UIImageView that has a UIPanGestureRecognizer attached. Its a subview of yellow area.
  4. Red item can be dragged, as long as the dragging starts from inside the live (yellow) area.

On the situation on the image shown above, I want to be able to drag the red item from any point on its surface. (not only from the area where it intersects the (yellow) area)

Any ideas?

Thanks!

dornad
  • 1,274
  • 3
  • 17
  • 36

2 Answers2

2

Views don't respond to touches when they are outside the bounds of their superview. You can fix the problem by making the red view a subview of the blue view instead of the yellow one.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

rdelmar has the cleanest way to do that.

But if you want to keep your view architecture, you can make a YellowClass, subclass of UIImageView for your yellow view. And implement the following code in your YellowClass:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{   
    if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
        for (UIView *subview in self.subviews.reverseObjectEnumerator) {
            CGPoint subPoint = [subview convertPoint:point fromView:self];
            UIView *result = [subview hitTest:subPoint withEvent:event];
            if (result != nil) {
                return result;
            }
        }
    }

    return nil;
}

YellowView subviews that are outside yellowView will respond to touch.

Read from this post.

Community
  • 1
  • 1
The Windwaker
  • 1,054
  • 12
  • 24