先上 GitHub地址
GLWaveView 介绍
一个自带波形动画的View, 可以添加多层波浪且方便自定义, 三行代码实现波形效果.
使用方法
- 创建并添加 GLWaveView 到视图当中
- 给 GLWaveView 对象添加 GLWave
- 调用 startWaveAnimate
完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| - (void)viewDidLoad {
[super viewDidLoad]; GLWaveView *view = [[GLWaveView alloc] initWithFrame:self.view.bounds]; GLWave *waveA = [GLWave defaultWave]; waveA.offsetX = 100; waveA.offsetY = 300; waveA.height = 20; waveA.width = 550; waveA.speedX = 6; waveA.fillColor = [UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:0.450].CGColor; GLWave *waveB = [GLWave defaultWave]; waveB.offsetX = 300; waveB.offsetY = 305; waveB.height = 15; waveB.width = 750; waveB.speedX = 9; waveB.fillColor = [UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:0.250].CGColor; [view addWave:waveB]; [view addWave:waveA];
[self.view addSubview:view]; [view startWaveAnimate]; }
|
GLWave
为了方便理解和配置动画参数 GLWave 的所有单位均以屏幕像素为单位.
GLWave 有如下 public property:
1 2 3 4 5 6 7 8
| @property (nonatomic, assign) CGFloat offsetX; @property (nonatomic, assign) CGFloat offsetY;
@property (nonatomic, assign) CGFloat height; @property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat speedX; @property (nonatomic, assign) CGFloat speedY;
|
如下图所示, width 就是波形一个周期的宽度, height 就是波形的振幅, speedX 就是每1/60秒波形x轴方向上位移的距离