1

我制作了一个自定义圆形视图,如何检测圆形的某些部分或部分。我已经尝试过使用触摸

- (BOOL)validatePoint:(CGPoint)myPoint
{
    // calculate how far from centre we are with Pythagorean
    // √ a2 + b2
    CGFloat a = abs(myPoint.x - (self.bounds.size.width/2));
    CGFloat b = abs(myPoint.y - (self.bounds.size.height/2));
    CGFloat distanceFromCentre = sqrt(pow(a,2) + pow(b,2));

    if((distanceFromCentre > self.minRadiusSize) && (distanceFromCentre < radius)){
        return YES;
    }else{
        // not inside doughnut
        return NO;
    }
}

但它检测整个我的观点。

4

1 回答 1

1
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    BOOL transparent=NO;

    CGPoint touchLocation = [event  locationInView:yourViewName];

    if(CGRectContainsPoint(yourViewName.frame, touchLocation))
    {
        NSLog(@"Found =%d",i);

        transparent=YES;
    }

    return transparent;
}

无论您是否在视图中点击,这都会返回您。

于 2013-08-12T12:44:44.990 回答