iOS 小小的加載動(dòng)畫

#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);

//組合動(dòng)畫

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 顯式動(dòng)畫 顯式動(dòng)畫,它能夠?qū)σ恍傩宰鲋付ǖ淖远x動(dòng)畫,或者創(chuàng)建非線性動(dòng)畫,比如沿著任意一條曲線移動(dòng)。 屬性動(dòng)畫 ...
    清風(fēng)沐沐閱讀 2,096評(píng)論 1 5
  • Core Animation Core Animation,中文翻譯為核心動(dòng)畫,它是一組非常強(qiáng)大的動(dòng)畫處理API,...
    45b645c5912e閱讀 3,158評(píng)論 0 21
  • 專用圖層 簡(jiǎn)書很多標(biāo)簽不支持,以下目錄跳轉(zhuǎn)沒(méi)用?。?! CAShapeLayer CATextLayer CATra...
    百草紀(jì)閱讀 1,411評(píng)論 0 4
  • 在iOS實(shí)際開(kāi)發(fā)中常用的動(dòng)畫無(wú)非是以下四種:UIView動(dòng)畫,核心動(dòng)畫,幀動(dòng)畫,自定義轉(zhuǎn)場(chǎng)動(dòng)畫。 1.UIView...
    請(qǐng)叫我周小帥閱讀 3,324評(píng)論 1 23
  • 01一封郵件 孩子出生后,做媽的就和她有了無(wú)限的牽掛,生活的重心也是圍繞著她轉(zhuǎn)了。最近因?yàn)榕畠荷蠈W(xué),在接送孩子上學(xué)...
    夢(mèng)在雨巷閱讀 378評(píng)論 0 0

友情鏈接更多精彩內(nèi)容