画水波纹。 博客分类: iOS Objective-C
#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);
}
上一篇: asp.net显示页面执行时间
下一篇: 第1章 Vue.js概述(读书笔记)
推荐阅读
-
画水波纹。 博客分类: iOS Objective-C
-
你画我猜 博客分类: Java
-
移植 Cocos2d IOS 到 Cocos2d-x Android 设备上 博客分类: cocos2d-x iosandroid
-
移植 Cocos2d IOS 到 Cocos2d-x Android 设备上 博客分类: cocos2d-x iosandroid
-
linux下编译objectc 博客分类: ios gcc
-
LLVM compiler 4.0带来的Objective-C新语法特性 博客分类: ios llvm4.0ios编译器新特性
-
iOS使用LLDB调试 博客分类: ios lldbgdbmac
-
ios的safari使用自制ca证书测试webrtc 博客分类: nginxwebrtc safaringinx
-
精通iOS开发(第5版) 博客分类: 计算机图书 iosicloudxcode
-
IOS游戏引擎列表 博客分类: Coco2d-x cocos2d