views:

40

answers:

1

Basically...

I have a UIScrollView subclass which you can add a target and selector too, which get fired if a touch event is detected within the view. I am using the scroll view as an image gallery, and the touch inside the scroll view is used to fade out the HUD components (UItoolBar, etc):

@implementation TouchableScrollView

- (void)addTarget:(id)_target withAction:(SEL)_action
{
    target = _target;
    action = _action;
    shouldRun = NO;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    shouldRun = YES;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    shouldRun = NO;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(shouldRun)
    {
        shouldRun = NO;
        [target performSelector:action];
    }
}

@end

I then have another custom UIView added as a subview to this which has the following set (both of which I have played around with):

self.userInteractionEnabled = YES;
self.exclusiveTouch = YES;

and uses the following to trigger an animation:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

The problem is even when the custom UIView detects the touch and responds (by flipping itself over), the UIScrollView selector also gets fired causing everything to fade out.

Please help, I'm totally stuck?!

A: 

better to use this in custom ScrollView class

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if (!self.dragging) { [self.nextResponder touchesEnded: touches withEvent:event]; }
[super touchesEnded: touches withEvent: event];

self.nextResponder is scrollView subViews. so event other then dragging (scrolling) will be handled by your main viewController . in main View controller inherit touch event method. there u can check for touch event for particular view or image view.

pawan.mangal
Ok I managed to solve this in rather a hacky way (boooooo). I just added a property to the UIScrollView subclass so you can set shouldRun to NO, meaning it will never fire the UIScrollView touch event when the other child view is touched :)
Jonathan Williamson