// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
// ViewController.m
#import "ViewController.h"
#import "UIView+Frame.h"
//屏幕寬高
#define screenW [UIScreen mainScreen].bounds.size.width
#define screenH [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@end
@implementation ViewController
/*
主要實現思路:
1.創建形狀圖層
2.創建復制圖層
3.創建透明度動畫
4.創建縮放動畫
5.創建動畫組把2個動畫添加進去
6.把動畫組添加到形狀圖層
*/
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setUp];
}
- (void)setUp {
UIView *animBack = [[UIView alloc] init];
animBack.width = screenW;
animBack.height = screenW;
animBack.center = self.view.center;
[self.view addSubview:animBack];
// 形狀圖層
CAShapeLayer *shapL = [CAShapeLayer layer];
shapL.frame = animBack.bounds;
shapL.fillColor = [UIColor redColor].CGColor;
shapL.path = [UIBezierPath bezierPathWithOvalInRect:shapL.bounds].CGPath;
// shapL.path = [UIBezierPath bezierPathWithRect:shapL.bounds].CGPath;
// 這句代碼不加的話,程序一起來,就會出現一個很大的紅色的圓
shapL.opacity = 0;
// 復制圖層
CAReplicatorLayer *repL = [CAReplicatorLayer layer];
repL.frame = animBack.bounds;
// 復制的份數算自己本身一份
repL.instanceCount = 3;
// 每一份顯示的間隔時間
repL.instanceDelay = 0.5;
[animBack.layer addSublayer:repL];
// 把形狀圖層添加到復制層中去
[repL addSublayer:shapL];
// 添加透明動畫
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.fromValue = @(0.3);
anim.toValue = @(0);
// 添加放大動畫
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform"];
anim2.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0, 0, 0)];
anim2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 0)];
// 創建動畫組
CAAnimationGroup *groupA = [CAAnimationGroup animation];
groupA.animations = @[anim, anim2];
groupA.duration = 3.0;
groupA.repeatCount = HUGE;
// 給形狀圖層添加動畫
[shapL addAnimation:groupA forKey:nil];
}
@end
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。