以下のコードでサークルを作成しました
//Color Declaration
UIColor *color = [UIColor colorWithRed:0 green:0.429 blue:0 alpha:1];
//Drawing Circle
CGRect circleRect = CGRectMake(20, 20, 170, 170);
UIBezierPath *circlePath = [UIBezierPath bezierPath];
[circlePath addArcWithCenter:CGPointMake(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect))
radius:CGRectGetWidth(circleRect)/2 startAngle:0 * M_PI/180
endAngle:289 * M_PI/180
clockwise:YES];
[circlePath addLineToPoint:CGPointMake(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect))];
[circlePath closePath];
[color setFill];
[circlePath fill];
以下のコードを使用して、円の領域でタッチコードを検証しました。
- (BOOL)validatePoint:(CGPoint)myPoint
{
// calculate how far from centre we are with Pythagorean
// √ a2 + b2
CGFloat a = abs(myPoint.x - (self.view.bounds.size.width/2));
CGFloat b = abs(myPoint.y - (self.view.bounds.size.height/2));
CGFloat distanceFromCentre = sqrt(pow(a,2) + pow(b,2));
if((distanceFromCentre > self.minRadiusSize) && (distanceFromCentre < self.maxRadiusSize)){
return YES;
}else{
// not inside doughnut
return NO;
}
}
上記のコードで Circle を検証しました。上記のコードが true の場合、Circle にタッチを追加できます。
同様に、円のセクター (部分) を検証する必要があります。
私の要件は、サークルのセクターを検証する必要があるということです。描かれた円のセクター(部分)を検出する必要がありました。私はフォーミュラを持ってい
[Area of Sector = ½ × (θ × π/180) × r2 (when θ is in degrees)]
ます。