iOS 小小的加载动画

#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 显式动画 显式动画,它能够对一些属性做指定的自定义动画,或者创建非线性动画,比如沿着任意一条曲线移动。 属性动画 ...
    清风沐沐阅读 6,143评论 1 5
  • Core Animation Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,...
    45b645c5912e阅读 8,204评论 0 21
  • 专用图层 简书很多标签不支持,以下目录跳转没用!!! CAShapeLayer CATextLayer CATra...
    百草纪阅读 5,130评论 0 4
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 8,404评论 1 23
  • 01一封邮件 孩子出生后,做妈的就和她有了无限的牵挂,生活的重心也是围绕着她转了。最近因为女儿上学,在接送孩子上学...
    梦在雨巷阅读 2,675评论 0 0

友情链接更多精彩内容