音量震动条

1.首先在storyboard上放一个lightView。
2.控制器里代码实现。

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *lightView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // CAReplicatorLayer复制图层,可以把图层里面所有子层复制
    // 创建复制图层
    CAReplicatorLayer *repL = [CAReplicatorLayer layer];
    
    repL.frame = _lightView.bounds;
    
    [_lightView.layer addSublayer:repL];
    
    CALayer *layer = [CALayer layer];
    
    layer.anchorPoint = CGPointMake(0.5, 1);
    layer.position = CGPointMake(15, _lightView.bounds.size.height);
    layer.bounds = CGRectMake(0, 0, 30, 150);
    
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    
    [repL addSublayer:layer];
    
    CABasicAnimation *anim = [CABasicAnimation animation];
    
    anim.keyPath = @"transform.scale.y";
    
    anim.toValue = @0.1;
    
    anim.duration = 0.5;
    
    anim.repeatCount = MAXFLOAT;
    
    // 设置动画反转
    anim.autoreverses = YES;
    
    
    [layer addAnimation:anim forKey:nil];
    
    
    // 复制层中子层总数
    // instanceCount:表示复制层里面有多少个子层,包括原始层
    repL.instanceCount = 3;
    
    // 设置复制子层偏移量,不包括原始层,相对于原始层x偏移
    repL.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
    
    // 设置复制层动画延迟时间
    repL.instanceDelay = 0.1;
    
    // 如果设置了原始层背景色,就不需要设置这个属性
    repL.instanceColor = [UIColor greenColor].CGColor;
    
    repL.instanceGreenOffset = -0.3;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,588评论 25 709
  • 室友昨天跟我说,刘清源,你怎么越来越胆小了?还那么怂? 是因为在健身房吹头发被人插队,我一句话都没说,默默排在后面...
    刘清源啊她说阅读 201评论 6 0
  • 夜已深,万籁俱寂,没有月光,窗外灯火寥寥落落,无端感到冷清。 每天数着同样的夜景,不同的是有时月辉满天,有时漆黑一...
    淡光浅影阅读 298评论 0 0
  • 小时候,我也有一个书柜,书柜里面,也放着各种各样的书,有历史书,有唐诗三百首,有《安徒生童话》,有不多的小...
    小妮可爱阅读 148评论 0 0