0
我想將包含CABasicAnimation的自定義UIView添加到UITableViewCell。我這個做以下方式UITableView addsubview crahes
if(self.pie_chart_view == nil)
self.pie_chart_view = [[PieChartView alloc] initWithFrame:CGRectMake(0.f, 0.f, 30.f, 30.f)];
[pie_chart_view animate_progress_from:0.0 to:1.0 with_duration:5.0];
[cell.contentView addSubview:pie_chart_view];
但是,代碼崩潰,如下面的截圖演示:
崩潰顯然是在下面的代碼段
- (void)drawInContext:(CGContextRef)context {
CGRect circleRect = CGRectInset(self.bounds, 1, 1);
CGColorRef borderColor = [[UIColor whiteColor] CGColor];
CGColorRef backgroundColor = [[UIColor colorWithWhite:0 alpha: 0.75] CGColor];
CGContextSetFillColorWithColor(context, backgroundColor); <--- CRASHES ON THIS LINE WITH EXC_BAD_ACCESS
CGContextSetStrokeColorWithColor(context, borderColor);
CGContextSetLineWidth(context, 2.0f);
CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);
CGFloat radius = MIN(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect));
CGPoint center = CGPointMake(radius, CGRectGetMidY(circleRect));
CGFloat startAngle = -M_PI/2;
CGFloat endAngle = self.progress * 2 * M_PI + startAngle;
CGContextSetFillColorWithColor(context, borderColor);
CGContextMoveToPoint(context, center.x, center.y);
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0);
CGContextClosePath(context);
CGContextFillPath(context);
[super drawInContext:context];
}
引起但我不明白爲什麼它會崩潰。我的項目使用ARC。我在這裏錯過了什麼?