【问题标题】:CoreAnimation CAShapeLayer Animating Bezier PathCoreAnimation CAShapeLayer 动画贝塞尔路径
【发布时间】:2014-12-30 08:32:25
【问题描述】:

我希望 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 参数?

(抱歉代码乱七八糟)

【问题讨论】:

    标签: uibezierpath cabasicanimation


    【解决方案1】:

    您可以使用presentationLayer获取当前动画值

    CGFloat val = [[bezier.presentationLayer valueForKey:@"strokeEnd"] floatValue];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 2014-08-13
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多