基于iOS實(shí)現(xiàn)音樂(lè)震動(dòng)條效果
一、簡(jiǎn)單分析
音樂(lè)震動(dòng)條不需要與用戶交互。我們可以使用復(fù)制層來(lái)操作。添加震動(dòng)條。添加動(dòng)畫。
復(fù)制層說(shuō)明
//創(chuàng)建復(fù)制層
-(void)createRepl{
//復(fù)制層
CAReplicatorLayer * repL = [CAReplicatorLayer layer];
repL.frame = self.contentV.bounds;
//復(fù)制6份
repL.instanceCount = 6;
//形變,每一個(gè)形變都是相對(duì)于上一個(gè)復(fù)制出來(lái)的子層開(kāi)始的
repL.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
//動(dòng)畫延時(shí)執(zhí)行
repL.instanceDelay = 0.5;
///要設(shè)置復(fù)制層的顏色 原始層的顏色要設(shè)為白色.
repL.instanceColor = [UIColor redColor].CGColor;
[self.contentV.layer addSublayer:repL];
self.repL = repL;
}
二、代碼
//
// ViewController.m
// 03_UIView75_音樂(lè)震動(dòng)條
//
// Created by 杞文明 on 17/7/21.
// Copyright © 2017年 杞文明. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *contentV;
@property (weak,nonatomic) CAReplicatorLayer * repL;
@property (weak,nonatomic) CALayer * layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.創(chuàng)建復(fù)制層次
[self createRepl];
//2.添加音量震動(dòng)條
[self addVoiceBar];
//3.添加動(dòng)畫
[self addAnimation];
}
//創(chuàng)建復(fù)制層
-(void)createRepl{
//復(fù)制層
CAReplicatorLayer * repL = [CAReplicatorLayer layer];
repL.frame = self.contentV.bounds;
//復(fù)制6份
repL.instanceCount = 6;
//形變,每一個(gè)形變都是相對(duì)于上一個(gè)復(fù)制出來(lái)的子層開(kāi)始的
repL.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
//動(dòng)畫延時(shí)執(zhí)行
repL.instanceDelay = 0.5;
///要設(shè)置復(fù)制層的顏色 原始層的顏色要設(shè)為白色.
repL.instanceColor = [UIColor redColor].CGColor;
[self.contentV.layer addSublayer:repL];
self.repL = repL;
}
//添加音量震動(dòng)條
-(void)addVoiceBar{
CALayer * layer = [CALayer layer];
layer.frame = CGRectMake(0, self.contentV.bounds.size.height-150, 30, 150);
layer.backgroundColor = [UIColor whiteColor].CGColor;
layer.position = CGPointMake(0, self.contentV.bounds.size.height);
layer.anchorPoint = CGPointMake(0, 1);
[self.repL addSublayer:layer];
self.layer = layer;
}
//添加動(dòng)畫
-(void)addAnimation{
//添加動(dòng)畫 對(duì)y方向縮放
CABasicAnimation * anim = [CABasicAnimation animation];
//設(shè)置屬性
anim.keyPath = @"transform.scale.y";
anim.toValue = @0;
anim.repeatCount = MAXFLOAT;
anim.autoreverses = YES;
anim.duration = 0.5;
[self.layer addAnimation:anim forKey:nil];
}
@end
三、圖示

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS實(shí)現(xiàn)翻頁(yè)效果動(dòng)畫實(shí)例代碼
本篇文章主要介紹了iOS實(shí)現(xiàn)翻頁(yè)效果動(dòng)畫實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
解析iOS開(kāi)發(fā)中的FirstResponder第一響應(yīng)對(duì)象
這篇文章主要介紹了解析iOS開(kāi)發(fā)中的FirstResponder第一響應(yīng)對(duì)象,包括View的FirstResponder的釋放問(wèn)題,需要的朋友可以參考下2015-10-10
舉例講解設(shè)計(jì)模式中的原型模式在iOS應(yīng)用開(kāi)發(fā)中的作用
這篇文章主要介紹了設(shè)計(jì)模式中的原型模式在iOS應(yīng)用開(kāi)發(fā)中的作用,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-04-04
ios實(shí)現(xiàn)簡(jiǎn)易隊(duì)列
這篇文章主要為大家詳細(xì)介紹了ios實(shí)現(xiàn)簡(jiǎn)易隊(duì)列,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
iOS實(shí)現(xiàn)H5支付(微信、支付寶)原生封裝
這篇文章主要介紹了iOS實(shí)現(xiàn)H5支付(微信、支付寶)原生封裝,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
iOS逆向工程使用dumpdecrypted工具給App脫殼
這篇文章主要介紹了iOS逆向工程使用dumpdecrypted工具給App脫殼的相關(guān)資料,本文圖文并茂給大家介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09

