2014-12-30 2 views
0

Я хочу, чтобы endAngle увеличивался, так что время выглядит как время.CoreAnimation CAShapeLayer Animating Bezier Path

UIBezierPath *path = [UIBezierPath bezierPath]; 
CAShapeLayer *bezier = [[CAShapeLayer alloc] init]; 
bezier.path = path.CGPath; 

UIGraphicsBeginImageContext(size); 
context = UIGraphicsGetCurrentContext(); 
[path moveToPoint:center]; 
[path addArcWithCenter:center 
       radius:radius 
      startAngle:0 - M_PI_2 // zero degrees is east, not north, so subtract pi/2 
       endAngle:2 * M_PI * 0.25 - M_PI_2 // ditto 
      clockwise:YES]; 
[path closePath]; 
CGContextSetFillColorWithColor(context, [AppDelegate colorFromHexString:@"#888888" alpha:0.9].CGColor); 
[path fill]; 
UIImage *requestStatusCircleImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageView *requestStatusCircleImageView = [[UIImageView alloc]initWithImage:requestStatusCircleImage]; 
requestStatusCircleImageView.layer.rasterizationScale = [UIScreen mainScreen].scale; 
requestStatusCircleImageView.layer.shouldRasterize = YES; 
requestStatusCircleImageView.translatesAutoresizingMaskIntoConstraints = NO; 
[requestStatusCircleContainer addSubview:requestStatusCircleImageView]; 


Request Status Circle Image Constraints 
[requestStatusCircleContainer addConstraint:[NSLayoutConstraint constraintWithItem:requestStatusCircleImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:requestStatusCircleContainer attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]]; 
[requestStatusCircleContainer addConstraint:[NSLayoutConstraint constraintWithItem:requestStatusCircleImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:requestStatusCircleContainer attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]]; 

[self.view.layer addSublayer:bezier]; 

CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"endAngle"]; 
animateStrokeEnd.duration = 5.0; 
animateStrokeEnd.fromValue = [NSNumber numberWithFloat:0.0f]; 
animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f]; 
[bezier addAnimation:animateStrokeEnd forKey:@"endAngle"]; 

Как получить доступ к параметру endAngle из CABasicAnimation?

(извините за беспорядок кода)

ответ

1

Вы можете принять текущее анимированное значение, используя

представительский уровень
CGFloat val = [[bezier.presentationLayer valueForKey:@"strokeEnd"] floatValue]; 
Смежные вопросы