我使用EFCircularSlider顯示圓線和用戶將移動處理程序如下:爲什麼CGContext沒有繪製循環?
我已經完成了,除了在動畫行爲顯示紅線所有用戶的需求。我無法改變我的代碼。我試圖逐漸畫出這條弧線。我正在使用CGContext並在循環中顯示圓,而不是使用動畫。但它在循環結束時繪製圖像。我跟蹤下來,並確保環路得到正確調用如下:
我打電話的方法:
int tmp = self.angleFromNorth;
while (tmp<360) {
NSLog(@"tmp == %d",tmp);
tmp+=10;
[NSThread sleepForTimeInterval: 0.1];
[EFCircularTrig drawUnfilledArcInContext:ctx
center:self.centerPoint
radius:self.radius
lineWidth:self.lineWidth
fromAngleFromNorth:self.angleFromNorth
toAngleFromNorth:tmp];
[self setNeedsDisplay];
}
,然後它會正確打印線,但循環結束之後。當打印出所有的值時,它將顯示該行。但我想讓它與動畫類似。
+(void) drawUnfilledArcInContext:(CGContextRef)ctx
center:(CGPoint)center
radius:(CGFloat)radius
lineWidth:(CGFloat)lineWidth
fromAngleFromNorth:(CGFloat)fromAngleFromNorth
toAngleFromNorth:(CGFloat)toAngleFromNorth
{
float cartesianFromAngle = CompassToCartesian(ToRad(fromAngleFromNorth));
float cartesianToAngle = CompassToCartesian(ToRad(toAngleFromNorth));
CGContextAddArc(ctx,
center.x, // arc start point x
center.y, // arc start point y
radius, // arc radius from center
cartesianFromAngle, cartesianToAngle,
0); // iOS flips the y coordinate so anti-clockwise (specified here by 0) becomes clockwise (desired)!
CGContextSetLineWidth(ctx, lineWidth);
CGContextSetLineCap(ctx, kCGLineCapButt);
CGContextSetShadowWithColor(ctx, CGSizeMake(0,0), 1, [UIColor colorWithRed:(0/255.0) green:(173/255.0) blue:(238/255.0) alpha:1.0].CGColor);
CGContextDrawPath(ctx, kCGPathStroke);
NSLog(@"HERE");
}
輸出:
2016-09-06 22:52:48.950 EFCircularSlider[38301:288182] tmp == 22
2016-09-06 22:52:49.056 EFCircularSlider[38301:288182] HERE
2016-09-06 22:52:49.056 EFCircularSlider[38301:288182] tmp == 32
2016-09-06 22:52:49.161 EFCircularSlider[38301:288182] HERE
2016-09-06 22:52:49.162 EFCircularSlider[38301:288182] tmp == 42
2016-09-06 22:52:49.265 EFCircularSlider[38301:288182] HERE
2016-09-06 22:52:49.266 EFCircularSlider[38301:288182] tmp == 52
2016-09-06 22:52:49.371 EFCircularSlider[38301:288182] HERE
2016-09-06 22:52:49.372 EFCircularSlider[38301:288182] tmp == 62
2016-09-06 22:52:49.475 EFCircularSlider[38301:288182] HERE
2016-09-06 22:52:49.475 EFCircularSlider[38301:288182] tmp == 72
2016-09-06 22:52:49.580 EFCircularSlider[38301:288182] HERE
但是一旦循環完成圖紙會出現。我想讓它逐漸顯現。我很感激任何人都可以在這裏添加他們的經驗。
我還補充說: