ios开发oc高仿京东金融白条额度余额的 ios开发水波纹 ios开发水正弦曲线波纹 ios开发雷达扫描的动画效果

ios开发oc高仿京东金融白条额度余额的   ios开发水波纹   ios开发水正弦曲线波纹

直接上代码,复制粘贴就可以

vc里的

WaterRippleView *topView = [[WaterRippleView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];

    [self.view addSubview:topView];

view.h

#import <UIKit/UIKit.h>

@interface WaterRippleView : UIView

@property(nonatomic,assign)CGFloat progress;

@end

view.m

//

//  WaterRipple.m

//  waterRipple

//

//  Created by dongqiangfei on 2017/2/3.

//  Copyright © 2017年 dongqiangfei. All rights reserved.

//

#import "WaterRippleView.h"

#define waterColor1 [UIColor colorWithRed:118/255.0f green:165/255.0f blue:242/255.0f alpha:0.6]

#define waterColor2 [UIColor colorWithRed:118/255.0 green:165/255.0 blue:242/255.0 alpha:0.6]

#define BackGroundColor [UIColor colorWithRed:80/255.0f green:140/255.0f blue:238/255.0f alpha:1]

@implementation WaterRippleView

{

    //前面的波浪

    CAShapeLayer *_waterLayer1;

    CAShapeLayer *_waterLayer2;

    

    CADisplayLink *_disPlayLink;

    

    /**

     曲线的振幅

     */

    CGFloat _waterAmplitude;

    /**

     曲线角速度

     */

    CGFloat _waterPalstance;

    /**

     曲线初相

     */

    CGFloat _waterX;

    /**

     曲线偏距

     */

    CGFloat _waterY;

    

    /**

     曲线移动速度

     */

    CGFloat _waterMoveSpeed;

}

-(id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        self.backgroundColor = BackGroundColor;

        [self buildUI];

        [self buildData];

    }

    return self;

}

//初始化UI

-(void)buildUI

{

    //初始化波浪

    //第一层

    _waterLayer1 = [CAShapeLayer layer];

    _waterLayer1.fillColor = waterColor1.CGColor;

    _waterLayer1.strokeColor = waterColor1.CGColor;

    _waterLayer1.frame = CGRectMake(0, 0, 100, 100);

    

    //第二层

    _waterLayer2 = [CAShapeLayer layer];

    _waterLayer2.fillColor = waterColor2.CGColor;

    _waterLayer2.strokeColor = waterColor2.CGColor;

    _waterLayer2.frame = CGRectMake(0, 0, 100, 100);

    

    [self.layer addSublayer:_waterLayer1];

    [self.layer addSublayer:_waterLayer2];

}

//初始化数据

-(void)buildData

{

    //振幅

    _waterAmplitude = 8;

    //角速度

    _waterPalstance = M_PI/self.bounds.size.width;

    //偏距

    _waterY = 100;

    //初相

    _waterX = 0;

    //x轴移动速度

    _waterMoveSpeed = _waterPalstance * 5;

    //以屏幕刷新速度为周期刷新曲线的位置

    _disPlayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updatewater:)];

    [_disPlayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

}

/**

 保持和屏幕的刷新速度相同,iphone的刷新速度是60Hz,即每秒60次的刷新

 */

-(void)updatewater:(CADisplayLink *)link

{

    //更新X

    _waterX += _waterMoveSpeed;

    [self updatewater1];

    [self updatewater2];

}

//更新第一层曲线

-(void)updatewater1

{

    //波浪宽度

    CGFloat waterwaterWidth = self.bounds.size.width;

    //初始化运动路径

    CGMutablePathRef path = CGPathCreateMutable();

    //设置起始位置

    CGPathMoveToPoint(path, nil, 0, _waterY);

    //初始化波浪其实Y为偏距

    CGFloat y = _waterY;

    //正弦曲线公式为: y=Asin(ωx+φ)+k;

    for (float x = 0.0f; x <= waterwaterWidth ; x++) {

        y = _waterAmplitude * cos(_waterPalstance * x + _waterX) + _waterY;

        CGPathAddLineToPoint(path, nil, x, y);

    }

    //填充底部颜色

    CGPathAddLineToPoint(path, nil, waterwaterWidth, 200);

    CGPathAddLineToPoint(path, nil, 0, 200);

    CGPathCloseSubpath(path);

    _waterLayer1.path = path;

    CGPathRelease(path);

}

//更新第二层曲线

-(void)updatewater2

{

    //波浪宽度

    CGFloat waterwaterWidth = self.bounds.size.width;

    //初始化运动路径

    CGMutablePathRef path = CGPathCreateMutable();

    //设置起始位置

    CGPathMoveToPoint(path, nil, 0, _waterY);

    //初始化波浪其实Y为偏距

    CGFloat y = _waterY;

    //正弦曲线公式为: y=Asin(ωx+φ)+k;

    for (float x = 0.0f; x <= waterwaterWidth ; x++) {

        y = _waterAmplitude * sin(_waterPalstance * x + _waterX) + _waterY;

        CGPathAddLineToPoint(path, nil, x, y);

    }

    //添加终点路径、填充底部颜色

    CGPathAddLineToPoint(path, nil, waterwaterWidth, 200);

    CGPathAddLineToPoint(path, nil, 0, 200);

    CGPathCloseSubpath(path);

    _waterLayer2.path = path;

    CGPathRelease(path);

    

}

//设置需要显示的进度,y轴的更新会在[updatewaterY]方法中实现

-(void)setProgress:(CGFloat)progress

{

    _progress = progress;

}

 /*附加一个弹簧效果的代码

  animView =[[UIView alloc]init];

    animView.backgroundColor = [UIColor yellowColor];

    animView.frame = CGRectMake(100, 100, 30, 30);

    [self.view addSubview:animView];

    anim = [CASpringAnimation animation];

    anim.keyPath = @"position.x";

    anim.fromValue =@(animView.center.x);

    anim.toValue = @(animView.center.x+80);

    anim.initialVelocity = 3;

    anim.mass = 2;

    anim.stiffness = 100;

    anim.damping = 10;

    anim.initialVelocity = 10;

    anim.duration = anim.settlingDuration;

    [animView.layer addAnimation:anim forKey:@""];

*/

@end

//ios开发雷达扫描的动画效果  ios开发旋转图片

   int width = 200;

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 - width/2, 0, width, width)];

    imgView.image = [UIImage imageNamed:@"扫描背景"];

    [self.view addSubview:imgView];

    imgView_one1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, width)];

    imgView_one1.image = [UIImage imageNamed:@"扫描"];

    [imgView addSubview:imgView_one1];

    

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];

    rotationAnimation.duration = 2;//旋转一周需要多少时间

    rotationAnimation.cumulative = YES;

    rotationAnimation.repeatCount = 20*600;//旋转次数

    [imgView_one1.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

原文地址:https://www.cnblogs.com/godlovexq/p/6363189.html