我希望繪製一條曲線,直到它完成一個完整的旋轉並連接成爲一個完整的圓形,而不是圓形輪廓。這必須在幾秒鐘內動畫。iPhone:繪製一條曲線,直到它變成一個圓圈動畫
任何人都可以指向正確的方向嗎?我已經問過一個similar question這個問題,但是我錯誤地寫了這個問題,所以每個人都很難理解我的意思,於是就迷失在問題的海洋中。
任何幫助
[編輯]
非常感謝我目前子類的UIView和壓倒一切的drawRect。我發現代碼繪製一個實心圓,但我只需要中風。
- (void)drawRect:(CGRect)rect {
// Drawing code
CGRect allRect = self.bounds;
CGRect circleRect = CGRectInset(allRect, 2.0f, 2.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBStrokeColor(context, self.strokeValueRed, self.strokeValueGreen, self.strokeValueBlue, self.strokeValueAlpha); // white
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 0.1f); // translucent white
CGContextSetLineWidth(context, self.lineWidth);
CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);
// Draw progress
CGPoint center = CGPointMake(allRect.size.width/2, allRect.size.height/2);
CGFloat radius = (allRect.size.width - 4)/2;
CGFloat startAngle = - ((float)M_PI/2); // 90 degrees
CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle;
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); // white
CGContextMoveToPoint(context, center.x, center.y);
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
[編輯#2]
我改變了代碼刪除所有的填充引用,但現在它不是畫什麼:(任何想法?
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect allRect = self.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBStrokeColor(context, self.strokeValueRed, self.strokeValueGreen, self.strokeValueBlue, self.strokeValueAlpha); // white
CGContextSetLineWidth(context, 5);
// Draw progress
CGPoint center = CGPointMake(allRect.size.width/2, allRect.size.height/2);
CGFloat radius = (allRect.size.width - 4)/2;
CGFloat startAngle = - ((float)M_PI/2); // 90 degrees
CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle;
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0);
CGContextStrokePath(context);
}
[編輯#3]解決方案
對我感覺就像一個正確的dickhead!問題是,筆畫顏色值沒有初始化,意味着線正在繪製,但顯然看不到它!!
感謝您的幫助! – bennythemink