美文网首页
iOS 小小的加载动画

iOS 小小的加载动画

作者: 曉風滿月 | 来源:发表于2016-04-07 17:08 被阅读0次

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

    [super viewDidLoad];

    CAShapeLayer *bottomLayer = [CAShapeLayer layer];

    bottomLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:100].CGPath;

    bottomLayer.backgroundColor = [UIColor orangeColor].CGColor;

    bottomLayer.lineWidth = 5;

    bottomLayer.fillColor = [UIColor whiteColor].CGColor;

    bottomLayer.strokeColor = [UIColor purpleColor].CGColor;

    [self.view.layer addSublayer:bottomLayer];

    CAShapeLayer *ovalShaper = [CAShapeLayer layer];

    ovalShaper.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 100, 100)].CGPath;

    ovalShaper.lineCap = kCALineCapRound;

    ovalShaper.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:100].CGPath;

    ovalShaper.fillColor = [UIColor whiteColor].CGColor;

    ovalShaper.strokeColor = [UIColor redColor].CGColor;

    ovalShaper.lineWidth = 5;

    [self.view.layer addSublayer:ovalShaper];

    CABasicAnimation *startAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];

    startAnimation.fromValue = @(-1);

    startAnimation.toValue = @(1.0);

    CABasicAnimation *endAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

    endAnimation.fromValue = @(0.0);

    endAnimation.toValue = @(1);

    //组合动画

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.animations = @[startAnimation,endAnimation];

    group.duration = 1;

    group.repeatCount = CGFLOAT_MAX;

    group.fillMode = kCAFillModeForwards;

    group.removedOnCompletion = NO;

    [ovalShaper addAnimation:group forKey:nil];

    }

    @end

    相关文章

      网友评论

          本文标题:iOS 小小的加载动画

          本文链接:https://www.haomeiwen.com/subject/kismhttx.html