ios simple hud CAAnimation 简单示例

简单的 CABasicAnimation,CAShapeLayer 用法示例.

-(void)initAnimationLayer
{
    [self.hudLayer removeFromSuperlayer];
    
    UIBezierPath *path=[UIBezierPath bezierPath];
    float radius = self.bounds.size.width/2;
    [path addArcWithCenter:CGPointMake(radius, radius) radius:radius startAngle:-2*M_PI endAngle:0 clockwise:NO];
    
    self.hudLayer=[CAShapeLayer layer];
    _hudLayer.path=path.CGPath;
    
    _hudLayer.fillColor=[UIColor colorWithWhite:0 alpha:0.5].CGColor;
    
    _hudLayer.strokeColor=[UIColor colorWithWhite:1 alpha:0.7].CGColor;
    _hudLayer.lineWidth= MAX(5, radius/10);
    _hudLayer.lineCap = @"round";
    _hudLayer.bounds = self.bounds;
    _hudLayer.anchorPoint = CGPointMake(0.5, 0.5);
    _hudLayer.position = CGPointMake(radius, radius);

    _hudLayer.strokeStart = 1;
    [self.layer addSublayer:_hudLayer];
}
-(void)startAnimation
{
    [self initAnimationLayer];
    
    CABasicAnimation *anim=[CABasicAnimation animationWithKeyPath:@"strokeStart"];
    anim.duration=0.5;
    anim.fromValue=@(1);
    anim.toValue=@(0.9);
    
    anim.delegate = self;
    [_hudLayer addAnimation:anim forKey:nil];
    _hudLayer.strokeStart = 0.9;
    _hudLayer.strokeEnd = 1;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    CABasicAnimation *rotation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotation.duration=1;
    rotation.fromValue=@(0);
    rotation.toValue=@(M_PI*2);
    rotation.repeatCount = INT_MAX;
    
    [_hudLayer addAnimation:rotation forKey:nil];
}

文件: http://download.csdn.net/detail/li6185377/6030763


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值