Volume Vibration Bar:
If implemented?
Create 3 layers, play y-axis scale animations sequentially
Using Careplicatorlayer to achieve
1. What is Careplicatorlayer?
A layer that can copy its own child layer, and the copied layer and the native child layer have the same properties, positions, deformations, animations.
2. Careplicatorlayer Properties
instanceCount: Total number of child layers (including native sub-layers)
instanceDelay: Copy child layer animation delay duration
instanceTransform: Copy the sub-layer deformation (excluding the native child layer), each copy child layer is relative to the previous one.
instanceColor: The sub-layer color, which conflicts with the background color of the native sub-layer, so the two choose one setting.
instanceRedOffset、instanceGreenOffset、instanceBlueOffset、instanceAlphaOffset: The color channel offset, where each copy sub-layer is relative to the previous offset.
If you use Careplicatorlayer to implement
1. First create a copy layer, the music vibration bar layer is added to the copy layer, and then the child layer is copied.
CAReplicatorLayer *layer = [CAReplicatorLayer layer]; layer.frame = CGRectMake(5050200200); layer.backgroundColor = [UIColor lightGrayColor].CGColor; [self.view.layer addSublayer:layer];
2. First create a volume vibration bar, and set the animation, animation is to zoom around the bottom, set the anchor point
Calayer *bar = [Calayer layer];Bar. BackgroundColor= [Uicolor Redcolor]. Cgcolor;Bar. Bounds= CGRectMake (0,0, -, -);Bar. Position= Cgpointmake ( the, $);Bar. Anchorpoint= Cgpointmake (0.5,1);[Layer Addsublayer:bar];Cabasicanimation *anim = [cabasicanimation animation];Anim. KeyPath= @"Transform.scale.y";Anim. Tovalue= @(0.1);Anim. Autoreverses= YES;Anim. RepeatCount= Maxfloat;[Bar Addanimation:anim Forkey:nil];
3. Copying sub-layers
// 设置4个子层,3个复制层 4; // 设置复制子层的相对位置,每个x轴相差40 layer.instanceTransform = CATransform3DMakeTranslation(4000); // 设置复制子层的延迟动画时长 0.3;
Demo instance
https://github.com/esdeath/02–
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Analog volume vibration bars in iOS