MWWaterWaveProgressView的实现

percent(完成比例),speed(水波纹横向移动的速度),peak(峰值),period(周期数)

1.实现原理:两个视图:MWWaveCycleAnimationView,MWWaveProgressView

MWWaveCycleAnimationView:背景层,如果有外需要外框动画,这需要添加一层layer进行path动画

//为外围图片添加遮盖层

- (void)addMaskLayerOnCycleImage {

CGSize size = self.frame.size;

UIBezierPath *maskPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(size.width * 0.5, size.height * 0.5) radius:size.width * 0.5 - mCYCLEANIMATION_MARGIN * 0.5 startAngle:3 * M_PI_2 endAngle:-M_PI_2 clockwise:NO];

CAShapeLayer *maskLayer = [CAShapeLayer layer];

maskLayer.fillColor = [UIColor clearColor].CGColor;

maskLayer.strokeColor = [UIColor whiteColor].CGColor;

maskLayer.path = maskPath.CGPath;

maskLayer.lineWidth = mCYCLEANIMATION_MARGIN + 1;

[self.layer addSublayer:maskLayer];

_maskLayer = maskLayer;

// 为遮盖层添加动画效果

[self addBaseAnimationWithLayer:maskLayer];

}


// 遮盖层动画效果

- (void)addBaseAnimationWithLayer:(CAShapeLayer *)maskLayer {

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

anim.fromValue = @1;

anim.toValue = @0;

anim.duration = mMASKLAYER_DURATION;

anim.repeatCount =2;

anim.removedOnCompletion = NO;

anim.fillMode = kCAFillModeForwards;

[maskLayer addAnimation:anim forKey:@"MaskLayerAnimation"];

}

MWWaveProgressView:实现水波效果,正余弦函数计算path,添加layer,并在layer添加动画,动画的过程,就是path路径,调用strokeEnd。

#pragma mark **** 定时器事件

- (void)displayLinkAction {

_offSet -= _speed;

[self percentChange];

// 正弦曲线

CGMutablePathRef sinPath = [self pathWithCurveType:mCurveTypeSin];

_firstWaveLayer.path = sinPath;

CGPathRelease(sinPath);

// 余弦曲线

CGMutablePathRef cosPath = [self pathWithCurveType:mCurveTypeCos];

_secondWaveLayer.path = cosPath;

CGPathRelease(cosPath);

}

#pragma mark **** 通过曲线类型获得对应的曲线路径

- (CGMutablePathRef)pathWithCurveType:(mCurveType)curveType {

_waveHeight = (1 - _changePercent) * _height;

CGMutablePathRef mutablePath = CGPathCreateMutable();

CGPathMoveToPoint(mutablePath, nil, 0, _waveHeight);

CGFloat y;

for (CGFloat x = 0.0f; x < _width; x++) {

switch (curveType) {

case 0:

y = _peak * sin(_period * M_PI / _width * x + _offSet) + _waveHeight;

break;

case 1:

y = _peak * cos(_period * M_PI / _width * x + _offSet) + _waveHeight;

break;

default:

break;

}

CGPathAddLineToPoint(mutablePath, nil, x, y);

}

CGPathAddLineToPoint(mutablePath, nil, _width, _height);

CGPathAddLineToPoint(mutablePath, nil, 0, _height);

CGPathCloseSubpath(mutablePath);

return mutablePath;

}

效果图:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,573评论 6 30
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,147评论 5 13
  • Core Animation Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,...
    45b645c5912e阅读 3,071评论 0 21
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,169评论 1 23
  • #import "ChangeAnimationView.h" ``` @interface ChangeAnim...
    JinHuiZhang阅读 607评论 0 0