tutsorg
tutsorg

Reputation: 21

How to Detect Some Portion in View

I have made a Custom Circle View, How to Detect Some Portion or Part of Circle.I have Tried this using touches

- (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;
    }
}

But its Detecting Entire my View.

Upvotes: 1

Views: 60

Answers (1)

Aniket Kote
Aniket Kote

Reputation: 541

- (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;
}

This will return you whether you have tapped in view or not.

Upvotes: 1

Related Questions