音量振动条

音量振动条_第1张图片
效果图片来自网络

OC代码实现:

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIView*contentView;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

//复制层:复制里面的子层

CAReplicatorLayer*repL = [CAReplicatorLayerlayer];

repL.frame=_contentView.bounds;

//

instanceCount:表示复制层中有多少份子层,拷贝是instanceCount

- 1份

repL.instanceCount=4;

//设置复制子层偏移量,每个子层都会相对上一次偏移

repL.instanceTransform=CATransform3DMakeTranslation(40,0,0);

//延迟每个子层的动画,相对于上一个子层延迟

repL.instanceDelay=0.2;

//设置子层的颜色

repL.instanceColor= [UIColorcolorWithWhite:1alpha:0.2].CGColor;

[_contentView.layeraddSublayer:repL];

//红色的图层

CALayer*layer = [CALayerlayer];

layer.backgroundColor= [UIColorredColor].CGColor;

//layer.frame = CGRectMake(0, 100, 30, 100);

layer.anchorPoint=CGPointMake(0,1);

layer.position=CGPointMake(0,200);

layer.bounds=CGRectMake(0,0,30,100);

//把红色图层添加到复制层中

[repLaddSublayer:layer];

CABasicAnimation*anim = [CABasicAnimationanimation];

anim.keyPath=@"transform.scale.y";

anim.toValue=@0;

anim.duration=0.5;

//设置动画反转

anim.autoreverses=YES;

anim.repeatCount=MAXFLOAT;

[layeraddAnimation:animforKey:nil];

}

你可能感兴趣的:(音量振动条)