0
我一直在做循環控制,我做得很好,除了當我第一次進行渲染時,圖形從左上角出現。自定義控件左上角出現的iOS圖形
整個控件的子類型爲UIControl
,自定義CALayer
可以渲染一個圓。
這是呈現了一圈代碼:
- (void) drawInContext:(CGContextRef)ctx{
id modelLayer = [self modelLayer];
CGFloat radius = [[modelLayer valueForKey:DXCircularControlLayerPropertyNameRadius] floatValue];
CGFloat lineWidth = [[modelLayer valueForKey:DXCircularControlLayerPropertyNameLineWidth] floatValue];
//NSLog(@"%s, angle: %6.2f, radius: %6.2f, angle_m: %6.2f, radius_m: %6.2f", __func__, self.circleAngle, self.circleRadius, [[modelLayer valueForKey:@"circleAngle"] floatValue], [[modelLayer valueForKey:@"circleRadius"] floatValue]);
// draw circle arc up to target angle
CGRect frame = self.frame;
CGContextRef context = ctx;
CGContextSetShouldAntialias(context, YES);
CGContextSetAllowsAntialiasing(context, YES);
// draw thin circle
//CGContextSetLineWidth(context, <#CGFloat width#>)
// draw selection circle
CGContextSetLineWidth(context, lineWidth);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextAddArc(context, frame.size.width/2.0f, frame.size.height/2.0f, radius, 0.0f, self.circleAngle, 0);
CGContextStrokePath(context);
CGContextSetShouldAntialias(context, NO);
}
這裏有一個問題video。
如果仔細觀察,您會注意到以某種方式渲染圓圈並不會開始居中。它從左上角傾斜。 這隻會在首次執行動畫時發生。
我知道這可能發生,如果一個錯誤開始和結束的動畫提交塊,但我不使用它們在這裏。
萬一這裏是鏈接到這個控件的到位桶repo:
爲了使它工作,我把它放在'layoutSubviews'方法中。也許是因爲autolayout ..謝謝:) –