开发者

Detect touch on uiview under the UIButton when button is pressed

开发者 https://www.devze.com 2023-03-26 07:49 出处:网络
i am using a uiview parent view....overidded touch began and touch ended methods... when i added a UIButton as a subview in the view and touch on the button touchdown event is detected and associated

i am using a uiview parent view....overidded touch began and touch ended methods... when i added a UIButton as a subview in the view and touch on the button touchdown event is detected and associated method is called ...but touchbegan met开发者_开发知识库hod that was over ridden is not called...

what i want is when i touch the button the method associated with the touchdown event and touchBegan method of uiview both be called simultaneously...UIbutton is not passing the touch to its superview i.e. uiview.....? Any idea how to do that ? Thanks


I'm not sure exactly how to call two touchesBegan events simultaneously on two different views, but you probably want to override the hitTest:withEvent: method of UIView. This will allow you to catch a touch event on the view underneath the UIButton before it gets to the button (hitTests work from the window upwards to the foremost view).

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (passToSubviews)
    {
        return [super hitTest: point withEvent: event];
    }

    // otherwise stop the subview receiving touches
    if ([super hitTest: point withEvent: event])
    {
        return self;
    }

    return nil;     
}

Maybe this can help...

EDIT:

Just a guess but you could try:

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView* hitSubview = [super hitTest: point withEvent: event];
    if (hitSubview)
    {
         [self doTouchedInStuff];
         return hitSubview;
    }

    return self;         
}

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

    [super touchesBegan:touches withEvent:event];
} 
0

精彩评论

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

关注公众号