我有構建接口添加一個子視圖和一些子層的主要的UIView(containerView在下面的代碼)的方法:的iOS添加子視圖和子層多次
- (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];
}
我的問題是,如果我打電話這種方法多次,subview和sublayers每次添加,他們不重繪,而是我想。這是爲什麼發生?
全局(定義在@implementation中)但我每次都啓動它們的對象。如果我只是這樣做了一次,謝謝。 – Heisenberg
這是我的榮幸提供幫助。 :-) – shuvo