練習(xí)實(shí)現(xiàn)效果:
挑戰(zhàn)自我練習(xí):
一.CAReplicatorLayer屬性
@property NSInteger instanceCount;
要?jiǎng)?chuàng)建的拷貝數(shù),可以做成動(dòng)畫
@property BOOL preservesDepth;
定義這個(gè)層是否將它的子層壓平到它的平面上不(也就是說近零,它是否與轉(zhuǎn)換層相似,默認(rèn)NO)如果是,則應(yīng)用標(biāo)準(zhǔn)限制(參見CATransformLayer.h
@property CFTimeInterval instanceDelay;
延時(shí)多久創(chuàng)建一個(gè)映射layer
@property CATransform3D instanceTransform;
創(chuàng)建映射的CATransform3D位置變化
@property(nullable) CGColorRef instanceColor;
在原對象的基礎(chǔ)上添加的顏色,可做動(dòng)畫
@property float instanceRedOffset;
@property float instanceGreenOffset;
@property float instanceBlueOffset;
@property float instanceAlphaOffset;
在原對象基礎(chǔ)顏色上做變化,可做動(dòng)畫
二.實(shí)現(xiàn)效果
1.創(chuàng)建CAReplicatorLayer對象并設(shè)置響應(yīng)屬性
CAReplicatorLayer *replicator = [CAReplicatorLayer layer];
replicator.frame = CGRectMake(0, 100, KScreen_W / 4.0f, KScreen_W / 4.0f);
[self.view.layer addSublayer:replicator];
//映射layer對象的次數(shù)
replicator.instanceCount = 10;
//創(chuàng)建CATransform3D對象設(shè)置位置依次變化
CATransform3D transform = CATransform3DIdentity;
//每次角度變化2*M_PI / 10 ,Z軸稍微變化為止否則會(huì)重疊
transform = CATransform3DRotate(transform, M_PI / 5.0, 0, 0, 0.001);
replicator.instanceTransform = transform;
//設(shè)置顏色漸變
replicator.instanceBlueOffset = -0.2;
replicator.instanceGreenOffset = -0.2;
2.創(chuàng)建源對象,并設(shè)置給CAReplicatorLayer對象
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(KScreen_W / 8.0f - 2.5, 20.0f, 5.0f, 5.0f)];
maskLayer = [CAShapeLayer layer];
maskLayer.fillColor = [UIColor redColor].CGColor;
maskLayer.path = bezierPath.CGPath;
maskLayer.fillColor = [UIColor colorWithWhite:0.9 alpha:1].CGColor;
maskLayer.fillRule = kCAFillRuleEvenOdd;
[replicator addSublayer:maskLayer];
3.做旋轉(zhuǎn)動(dòng)畫
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI / 10 - 0.001 ];
rotationAnimation.duration = 0.05;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = CGFLOAT_MAX;
[replicator addAnimation:rotationAnimation forKey:@"aa"];
Copyright ? 2017年ZaneWangWang. All rights reserved.
持續(xù)更新中...