如何在自定义view确定你点击的位置位于哪个小的子视图


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

{

    [selftouchPoint:toucheswithEvent:event];

    [supertouchesBegan:toucheswithEvent:event];

}


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

{

    //Get the point user touched

    UITouch *touch = [touchesanyObject];

    // 关键代码

     CGPoint touchPoint = [touchlocationInView:self];

    UIView *subview = [selfhitTest:touchPointwithEvent:nil];


    if ([subviewisKindOfClass:[PNBarclass]] && [self.delegaterespondsToSelector:@selector(userClickedOnBarAtIndex:)]) {

        [self.delegateuserClickedOnBarAtIndex:subview.tag];

    }

}


你可能感兴趣的:(UIKit)