我希望endAngle增加,看起来时间已经不多了。
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"];
如何从CABasicAnimation访问endAngle参数?
(抱歉代码混乱)
答案 0 :(得分:1)
您可以使用presentationLayer
获取当前的动画值CGFloat val = [[bezier.presentationLayer valueForKey:@"strokeEnd"] floatValue];