日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

CAReplicatorLayer复制Layer和动画, 实现神奇的效果

發布時間:2025/3/17 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CAReplicatorLayer复制Layer和动画, 实现神奇的效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天我們看下CAReplicatorLayer,?官方的解釋是一個高效處理復制圖層的中間層。他能復制圖層的所有屬性,包括動畫。

一樣我們先看下頭文件

@interface CAReplicatorLayer : CALayer@property NSInteger instanceCount; //復制的個數 @property BOOL preservesDepth; //這是一個bool值,默認為No,如果設為Yes,將會具有3維透視效果 @property CFTimeInterval instanceDelay; //復制后的layer相比原來的距離 @property CATransform3D instanceTransform; //復制layer的坐標系/方向偏轉 @property(nullable) CGColorRef instanceColor;@property float instanceRedOffset; @property float instanceGreenOffset; @property float instanceBlueOffset; @property float instanceAlphaOffset;@end

我們可以通過CAReplicatorLayer實現很炫的動畫, 比如這個

上代碼:

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//創建一個紅色的圓形CALayerCALayer * layer = [CALayer layer];layer.bounds = CGRectMake(0, 0, 30, 30);layer.position = CGPointMake(self.view.center.x - 50, self.view.center.y - 50);layer.backgroundColor = [UIColor redColor].CGColor;layer.cornerRadius = 15;[self.view.layer addSublayer:layer];//創建一個透明度動畫CABasicAnimation * animation1 = [CABasicAnimation animationWithKeyPath:@"opacity"];animation1.fromValue = @(0);animation1.toValue = @(1);animation1.duration = 1.5;animation1.autoreverses = YES;//創建一個縮放動畫CABasicAnimation * animation2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];animation2.toValue = @(1.5);animation2.fromValue = @(0.5);animation2.duration = 1.5;animation2.autoreverses = YES;//創建一個動畫組, 將之前創建的透明度動畫和縮放動畫加入到這個動畫組中CAAnimationGroup * ani = [CAAnimationGroup animation];ani.animations = @[animation1,animation2];ani.duration = 1.5;ani.repeatCount = MAXFLOAT;ani.autoreverses = YES;//將動畫組添加到layer [layer addAnimation:ani forKey:nil];CAReplicatorLayer * rec = [CAReplicatorLayer layer];rec.instanceCount = 3;rec.instanceDelay = 0.5;rec.instanceTransform = CATransform3DMakeTranslation(50, 0, 0);[rec addSublayer:layer];[self.view.layer addSublayer:rec];CAReplicatorLayer * rec2 = [CAReplicatorLayer layer];rec2.instanceCount = 3;rec2.instanceDelay = 0.5;rec2.instanceTransform = CATransform3DMakeTranslation(0, 50, 0);[rec2 addSublayer:rec];[self.view.layer addSublayer:rec2]; }@end

利用CAReplicatorLayer可以實現很多神奇的效果, 大家可以在發揮下腦洞

?

轉載于:https://www.cnblogs.com/zhouxihi/p/6296019.html

總結

以上是生活随笔為你收集整理的CAReplicatorLayer复制Layer和动画, 实现神奇的效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。