Analog volume vibration bars in iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.