【发布时间】:2017-01-16 04:29:19
【问题描述】:
我有一个构建界面的方法,在主 UIView 中添加了一个 subView 和一些 subLayers(下面代码中的 containerView):
- (void)gradeAnimation:(NSNumber*)grade withDuration:(double)duration {
scoreLabel = [[UICountingLabel alloc] init];
scoreLabel.frame = CGRectOffset(_gradeLabel.frame, 0, 5);
[_containerView addSubview:scoreLabel];
// Other code
UIBezierPath *circlePathMin = [UIBezierPath bezierPathWithArcCenter:CGPointMake(_gradientView.center.x, _gradientView.center.y) radius:_gradientView.frame.size.height * 0.5 - 5 startAngle:-M_PI_4*1.2 endAngle:angle1 clockwise:YES];
circleMin = [CAShapeLayer layer];
circleMin.path = circlePathMin.CGPath;
circleMin.lineCap = kCALineCapButt;
circleMin.fillColor = [UIColor clearColor].CGColor;
circleMin.lineWidth = 14;
circleMin.strokeColor = [UIColor colorWithRed:246.0/255.0f green:246.0f/255.0f blue:246.0f/255.0f alpha:0.7f].CGColor;
circleMin.zPosition = 3;
[_containerView.layer addSublayer:circleMin];
UIBezierPath *circlePathMax = [UIBezierPath bezierPathWithArcCenter:CGPointMake(_gradientView.center.x, _gradientView.center.y) radius:_gradientView.frame.size.height * 0.5 - 5 startAngle:angle2 endAngle:5*M_PI_4*1.2 clockwise:YES];
circleMax = [CAShapeLayer layer];
circleMax.path = circlePathMax.CGPath;
circleMax.lineCap = kCALineCapButt;
circleMax.fillColor = [UIColor clearColor].CGColor;
circleMax.lineWidth = 14;
circleMax.strokeColor = [UIColor colorWithRed:246.0/255.0f green:246.0f/255.0f blue:246.0f/255.0f alpha:0.7f].CGColor;
circleMax.zPosition = 3;
[_containerView.layer addSublayer:circleMax];
UIBezierPath *circlePathMiddle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(_gradientView.center.x, _gradientView.center.y) radius:_gradientView.frame.size.height * 0.5 - 5 startAngle:angle1+offsetRight endAngle:angle2+offsetLeft clockwise:YES];
circleMiddle = [CAShapeLayer layer];
circleMiddle.path = circlePathMiddle.CGPath;
circleMiddle.lineCap = kCALineCapButt;
circleMiddle.fillColor = [UIColor clearColor].CGColor;
circleMiddle.lineWidth = 14;
circleMiddle.strokeColor = [UIColor colorWithRed:246.0/255.0f green:246.0f/255.0f blue:246.0f/255.0f alpha:0.7f].CGColor;
circleMiddle.zPosition = 3;
[_containerView.layer addSublayer:circleMiddle];
}
我的问题是,如果我多次调用此方法,每次都会添加子视图和子图层,并且不会像我想要的那样重绘它们。为什么会这样?
【问题讨论】:
标签: ios objective-c uiview subview