QuartzCore 之 CAReplicatorLayer.h
CAReplicatorLayer是一個layer容器,會對其中的subLayer進行復制和屬性偏移,通過它,可以建立出類似倒影的效果,也可以進行變換複製。Apple 提供的 API如下所示:
#import <QuartzCore/CALayer.h>
NS_ASSUME_NONNULL_BEGIN
CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
@interface CAReplicatorLayer : CALayer
//subLayer 複製的次數
@property NSInteger instanceCount;
//如果設定為YES,圖層將保持於CATransformLayer類似的性質和相同的限制
@property BOOL preservesDepth;
//如果進行動畫,副本延時一秒執行
@property CFTimeInterval instanceDelay;
//每個副本在 x , y , z 軸方向的改變
@property CATransform3D instanceTransform;
//副本顏色
@property(nullable) CGColorRef instanceColor;
//設定每個複製圖層相對上一個複製圖層的紅色偏移量
@property float instanceRedOffset;
//設定每個複製圖層相對上一個複製圖層的綠色偏移量
@property float instanceGreenOffset;
//設定每個複製圖層相對上一個複製圖層的藍色偏移量
@property float instanceBlueOffset;
//設定每個複製圖層相對上一個複製圖層的透明度偏移量
@property float instanceAlphaOffset;
@end
NS_ASSUME_NONNULL_END
例項一:(雷達波紋)
UIView *animationView = [[UIView alloc] init];
animationView.bounds = CGRectMake(0, 0, kScreenWidth, 200);
animationView.center = self.view.center;
animationView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:animationView];
CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
replicatorLayer.instanceCount = 3;
replicatorLayer.instanceDelay = 0.3;
[animationView.layer addSublayer:replicatorLayer];
//動畫圖層,就是不停變大的那個圓
animationLayer = [CAShapeLayer layer];
animationLayer.backgroundColor = [UIColor lightGrayColor].CGColor;
animationLayer.bounds = CGRectMake(0, 0, 20, 20);
animationLayer.cornerRadius = 20/2.0;
animationLayer.position = CGPointMake(kScreenWidth/2.0, 200/2.0);
animationLayer.opacity = 0.7;
[replicatorLayer addSublayer:animationLayer]; //把 動畫圖層(shaperLayer)關聯到 複製圖層(replicatorLayer)上
//放大動畫
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
NSValue *value = [NSValue valueWithCATransform3D:CATransform3DMakeScale(10, 10, 0.5)];
transformAnimation.toValue = value;
transformAnimation.duration = 2.0;
//透明度動畫 (也可以直接設定CAReplicatorLayer的instanceAlphaOffset來實現,學習中,目前實現效果不佳,請大神指教)
CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphaAnimation.fromValue = @(1.0);
alphaAnimation.toValue = @(0.0);
alphaAnimation.duration = 2.0;
CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.values = @[@1, @0.9, @0.8, @0.7, @0.6, @0.5, @0.4, @0.3, @0.2, @0.1, @0.0];
opacityAnimation.keyTimes = @[@0, @0.1, @0.2, @0.3, @0.4, @0.5, @0.6, @0.7, @0.8, @0.9, @1];
//動畫組
animationGroup = [CAAnimationGroup animation];
animationGroup.animations = @[transformAnimation,alphaAnimation];
animationGroup.duration = 2.0;
animationGroup.repeatCount = MAXFLOAT;
//開始動畫
[animationLayer addAnimation:animationGroup forKey:@"animationLayer"];
相關文章
- oracle之 RAC Interconnect之HAIPOracleAI
- 漢字之美,拼音之韻
- Python基礎之(三)之字典Python
- 設計模式之禪之代理模式設計模式
- 程式碼之美---遞迴之美遞迴
- 科學之抽象管理之提升抽象
- JavaScript之thisJavaScript
- 若之
- 深入Spring之IOC之載入BeanDefinitionSpringBean
- PHP之string之ord()函式使用PHP函式
- 《碼農翻身》之浪潮之巔的WebWeb
- vue 兄弟元件之間傳值之busVue元件
- 架構之爭,體制之惑(1)--產品經理模式之弊論架構模式
- 前端之資料模擬之Mock.js前端MockJS
- 軟體測試江湖之公會武器之爭
- Java常用資料結構之Set之TreeSetJava資料結構
- AI犯錯誰之過?切勿盲目相信之AI
- React之元件(component)之間的通訊React元件
- 計算機網路之HTTP之概況計算機網路HTTP
- 揭秘ORACLE備份之----RMAN之五(CATALOG)Oracle
- Android高階之十三講之安全方案Android
- QT之不同主機之間TCP通訊QTTCP
- 【Zookeeper】原始碼分析之持久化(二)之FileSnap原始碼持久化
- AMD and CMD are dead之KMD.js之懶JS
- 程式設計之美之買票找零程式設計
- Java物件之間的比較之equals和==Java物件
- 前端之HTML前端HTML
- Java 之 JDBCJavaJDBC
- css之定位CSS
- jQuery之documentFragmentjQueryFragment
- react之schedulerReact
- html之iframe,aHTML
- JS之DOMJS
- css之displayCSS
- 機器學習之皮毛機器學習
- .NET之WebAPIWebAPI
- Java之ServletJavaServlet
- Vuex之moduleVue