3

I have a transparent UIView on top of a UIScrollView. The UIView determines whether the scrollview is allowed to scroll or not by checking three touchesMoved events. After the events, I want the view to disable user interaction so scrolling will happen. The user shouldn't even notice the delay.

However, having set the view's userInteractionEnabled to NO, it keeps claiming all touchesMoved events until it is released. This means that the user is forced to let go of the view before being able to scroll.

Using hitTest won't work until the view has been released as well. hitTest does not get called while moving.

I would send the touch events to the UIScrollView, but it happily ignores those due to it having its own hidden touch handling.

Any way to make the UIView stop claiming touch events without having to let go of it?

Aberrant
  • 3,423
  • 1
  • 27
  • 38
  • maybe this will help? http://stackoverflow.com/questions/4530384/ignore-touch-event-and-let-the-view-below-it-handle-the-touch – mja Oct 10 '11 at 13:07
  • @mja I tried hitTest, but it seems it only gets called when the touch begins, not while moving. I'll add that to the question. Thanks though. – Aberrant Oct 10 '11 at 13:11
  • @jamapag: Oops. That should be userInteractionEnabled. I'll fix that. Thanks! – Aberrant Oct 10 '11 at 13:14

2 Answers2

3

Make the UIView hidden. According to the docs:

A hidden view disappears visually from its window and does not receive input events

See the class reference for more: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63
  • 1
    Using hidden = YES in stead of userInteractionEnabled = NO gives the same issue, all touchesMoved events are sent to the hidden view until the user lifts his/her finger. resignFirstResponder, which I encountered on the class reference, won't get it to work either. But thanks anyway. – Aberrant Oct 10 '11 at 14:13
3

try cancelling the touches:

How to cancel a sequence of UITouch events?

p.s. if necessary I assume you are propagating the touches to next responder:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [[self nextResponder] touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [[self nextResponder] touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [[self nextResponder] touchesEnded:touches withEvent:event];
}
Community
  • 1
  • 1
ader
  • 5,403
  • 1
  • 21
  • 26
  • My apologies, I didn't try it out yet. I found a work-around by replacing the vertical drag behaviour by vertical scrolling (not as obvious as it sounds, diagonal movement wasn't supposed to happen originally). I'd still like to know the answer to this, others too, probably, I'll make sure to check this when I have the time. – Aberrant Oct 12 '11 at 07:15