开发者

Parent UIScrollView detecting child UIView's touches

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, a开发者_开发知识库nd 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?!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜