水波电量提示

 

@interface VWWWaterView ()

{

    UIColor *_currentWaterColor;

    

    float _currentLinePointY;

    

    float a;

    float b;

    

    BOOL jia;

}

@end

 

 

@implementation VWWWaterView

 

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

         [self setBackgroundColor:[UIColor clearColor]];

        a = 1.5;

        b = 0;

        jia = NO;

        _currentWaterColor = [UIColor colorWithRed:0.3621 green:1.0 blue:0.0403 alpha:1.0];

        _currentLinePointY = frame.size.width*3/4;

        [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(animateWave) userInfo:nil repeats:YES];

    }

    return self;

}

 

-(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;

    

    [self setNeedsDisplay];

}

 

 

- (void)drawRect:(CGRect)rect

{

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGMutablePathRef path = CGPathCreateMutable();

       //画水

    CGContextSetLineWidth(context, 1);

    CGContextSetFillColorWithColor(context, [_currentWaterColor CGColor]);

    

    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);

}

 

posted @ 2016-03-30 21:53  塔里木小虫  阅读(36)  评论(0)    收藏  举报