ios开发oc高仿京东金融白条额度余额的 ios开发水波纹 ios开发水正弦曲线波纹 ios开发雷达扫描的动画效果
2018-04-20 16:14
656 查看
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"];
直接上代码,复制粘贴就可以
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"];
相关文章推荐
- ios开发oc高仿京东金融白条额度余额的 ios开发水波纹 ios开发水正弦曲线波纹 ios开发雷达扫描的动画效果
- iOS开发之iOS中的动画实现,通过CAShapeLayer、CAShapeLayer,CAReplicatorLayer实现炫酷的动画、雷达效果,波纹效果,咻一咻效果。iOS核心动画实现。
- iOS开发雷达动画效果实现
- CADisplayLink与CAShapeLayer配合实现的水波纹效果(iOS开发 水波纹效果)
- iOS 接入 芝麻信用 iOS开发-Xcode-OC_JSON_Plugin-将Json直接转成模型对应属性 iOS开发-直播APP常用动画效果
- iOS应用开发之:常用三种动画表现效果
- IOS开发-UIView之动画效果的实现方法(合集)
- oc开发笔记5 iOS addsubview 使用过场动画
- iOS开发-UIView之动画效果的实现方法
- iOS开发之各种动画各种页面切面效果
- ios开发之--简单动画效果的添加
- TWaver动画之雷达扫描效果
- IOS开发-UIView之动画效果的实现方法(合集)
- IOS开发UIView之动画效果的实现方法(合集)
- iOS开发--UIPickerView的动画效果
- iOS开发中实现动画效果的多种方法
- iOS开发-OC之知识树,知识点(包括对象、Block、消息转发、GCD、运行时、runloop、动画、Push、KVO、tableview,UIViewController、提交AppStore)
- iOS开发(OC)——绕圆心旋转效果
- iOS雷达和类似水波纹效果的实现
- OC IOS开发使用半透明模糊效果方法合集