水纹波浪效果动画

githubhttps://github.com/potato512/SYAnimation

效果图:

水纹波浪效果动画_第1张图片

示例代码见"githubhttps://github.com/potato512/SYAnimation"中的"SYWaterAnimationView"类。

使用:

// 使用方法1
SYWaterAnimationView *waterView = [[SYWaterAnimationView alloc] initWithFrame:CGRectMake(10.0, 120.0, (self.view.frame.size.width - 10.0 * 2), 100.0) waveColor:[UIColor colorWithRed:73/255.0 green:142/255.0 blue:178/255.0 alpha:0.5] waterColor:[UIColor colorWithRed:73/255.0 green:142/255.0 blue:178/255.0 alpha:0.5]];
waterView.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.3];
waterView.tag = 1000;
[self.view addSubview:waterView];
// 使用方法2
SYWaterAnimationView *waterView2 = [[SYWaterAnimationView alloc] initWithFrame:CGRectMake(10.0, 230.0, (self.view.frame.size.width - 10.0 * 2), 100.0)];
waterView2.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.3];
waterView2.waterColor = [UIColor redColor];
waterView2.waveColor = [UIColor greenColor];
waterView2.waveAmplitude = 11.0;
waterView2.waveSpeed = 0.05;
waterView2.wavePeriod = (M_PI) / self.view.frame.size.width;
waterView2.waveWidth = self.view.frame.size.width;
waterView2.waveCurrentHeight = 20.0;
waterView2.tag = 1001;
[self.view addSubview:waterView2];

特别注意,需要在视图控制器被释放时释放动画资源,避免造成内存泄露

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    SYWaterAnimationView *waterView = (SYWaterAnimationView *)[self.view viewWithTag:1000];
    [waterView animationWaterInvalidate];
    
    waterView = (SYWaterAnimationView *)[self.view viewWithTag:1001];
    [waterView animationWaterInvalidate];
}




你可能感兴趣的:(iOS,动画)