0

アークの作成に関する Ray Wenderlich のチュートリアルに従っていました。

http://www.raywenderlich.com/33193/core-graphics-tutorial-arcs-and-paths

-私がやろうとしているのは、ポイントa(固定ポイント)から始めて、ユーザーが画面に触れた場所を特定することです.+ポイントAの場合、そのポイントまで円弧を描きたいです。エラーは返されませんが、パスをストロークすることもできません。誰かが以下のコードを確認して、私が間違っていることを確認できますか?

    @implementation KIP_Arc

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void) setArc {

    //set the frame
    float frameX = _startPoint.x;
    float frameY = _startPoint.y;
    float frameW = _endPoint.x;
    float frameH = 50.0;

    [self setFrame:CGRectMake(frameX, frameY, frameW, frameH)];
    self.backgroundColor = [UIColor clearColor];

}

- (BOOL)isFlipped {
    return YES;
}


- (void)drawRect:(CGRect)rect  {

    [[UIColor blackColor] set];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGRect arcRect = self.frame;
    CGMutablePathRef arcPath = [self createArcPathFromBottomOfRect:arcRect:25.0];
    CGContextAddPath(context, arcPath);
    CGContextClip(context);
    CGContextFillPath(context);
    CGContextRestoreGState(context);

    CFRelease(arcPath);

}

- (CGMutablePathRef) createArcPathFromBottomOfRect : (CGRect) rect : (CGFloat) arcHeight {

    CGRect arcRect = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height - arcHeight, rect.size.width, arcHeight);

    CGFloat arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8*arcRect.size.height));
    CGPoint arcCenter = CGPointMake(arcRect.origin.x + arcRect.size.width/2, arcRect.origin.y + arcRadius);

    CGFloat angle = acos(arcRect.size.width / (2*arcRadius));
    CGFloat startAngle = radians(180) + angle;
    CGFloat endAngle = radians(360) - angle;


    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddArc(path, NULL, arcCenter.x, arcCenter.y, arcRadius, startAngle, endAngle, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMinY(rect));
    CGPathAddLineToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMinY(rect));
    CGPathAddLineToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMaxY(rect));

    return path;
}

static inline double radians (double degrees){
    return degrees * M_PI/180;
}
4

1 に答える 1