#import "VWWWaterView.h"
@interfaceVWWWaterView ()
{
UIColor *_currentWaterColor;
float _currentLinePointY;///水的top。
float a;///水上下抖动的幅度。。。
float b;
BOOL jia;
}
@end
@implementation VWWWaterView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[selfsetBackgroundColor:[UIColorclearColor]];
a = 1.5;
b = 0;
jia = NO;
_currentWaterColor = [UIColorblueColor];
_currentLinePointY = 111;
[NSTimerscheduledTimerWithTimeInterval:0.02target:selfselector:@selector(animateWave) userInfo:nilrepeats:YES];
}
returnself;
}
-(void)animateWave
{
if (jia) {
a += 0.01;
}else{
a -= 0.01;
}
if (a<=1) {
jia = YES;
}
if (a>=1.5) {
jia = NO;
}
b+=0.1;
[selfsetNeedsDisplay];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
//画水
CGContextSetLineWidth(context, 1);
CGContextSetFillColorWithColor(context, [_currentWaterColorCGColor]);
float y=_currentLinePointY;
CGPathMoveToPoint(path, NULL, 0, y);
for(float x=0;x<=320;x++){
y= a * sin( x/180*M_PI + 4*b/M_PI ) * 5 + _currentLinePointY;
CGPathAddLineToPoint(path, nil, x, y);
}
CGPathAddLineToPoint(path, nil, 320, rect.size.height);
CGPathAddLineToPoint(path, nil, 0, rect.size.height);
CGPathAddLineToPoint(path, nil, 0, _currentLinePointY);
CGContextAddPath(context, path);
CGContextFillPath(context);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(path);
}
相关推荐
水波纹制作器——SqR,可将图片制作成水波纹动画,效果逼真。
2.保证无毒 3.简单,方便,实用 4.实例可以自行改用 5.如有非法,本人无法律责任,由改动代码人负责! 6.更多本人作品,查找标签“朱建强” 7.请下载,杀毒后再使用!
非常炫的水波纹特效 包含 winform版源码 和 wpf版源码
unity用shader来实现2D涟漪/水波纹特效
根据自己的博文写的一个Android水波纹过渡动画,相信你一定喜欢的,十分炫酷!
WaterRippleView 水波纹动画视图
此Dome在高德地图上水波纹扩散的效果,地图缩放水波纹也跟着缩放
防百度阅读标题栏水波纹效果 动画 实现Viewpager切换界面导航栏水波纹动画效果
百度地图自定义水波纹(雷达)效果覆盖物
Android 点击出现水波纹效果,支持两种布局LinearLayout和RelativeLayout
利用动画或者自定义实现Android水波纹效果,不需要UI切图,快捷便利的实现,你值得拥有。详细讲解请看博客:https://blog.csdn.net/lou_liang/article/details/83502810
react native 实现水波纹效果,效果非常棒哦
类似水波纹效果,可用于下拉刷新。 实现原理: 由水波纹的特点类似于波浪形状,因此可根据正弦函数f(x) = Asin(ωx φ)来实现波浪的形状。 A震动时所能达到的最高和最低点; 正弦完整的周期T = 2π/ω,因此周期越...
二阶贝塞尔曲线实现水波纹效果,值得一看,代码写的很清楚
javascript实现水波纹子,就像动画一样,值得借鉴
Android自定义View实现水波纹效果,对Path的学习,实现一个水波纹效果
Android自定义View 实现水波纹动画引导 csdn博客地址:http://blog.csdn.net/chenzheng8975/article/details/54580390
iOS开发中动画特效,水波纹形式,从中心向外扩散,颜色渐变
WaveView优雅的水波纹动画实现.zip,WaveView 一个水波纹动画控件视图,支持波纹数,波纹振幅,波纹颜色,渐变色,波纹速度,波纹方向等属性完全可配。
用GDI 绘制 做的 水波纹的控件,很久之前写的,其实很多地方可以再优化,例如做区域绘制提高效率等,其实5分少了