iOS 进度条加载安装动画.docx

上传人:b****6 文档编号:5635185 上传时间:2022-12-29 格式:DOCX 页数:13 大小:37.05KB
下载 相关 举报
iOS 进度条加载安装动画.docx_第1页
第1页 / 共13页
iOS 进度条加载安装动画.docx_第2页
第2页 / 共13页
iOS 进度条加载安装动画.docx_第3页
第3页 / 共13页
iOS 进度条加载安装动画.docx_第4页
第4页 / 共13页
iOS 进度条加载安装动画.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

iOS 进度条加载安装动画.docx

《iOS 进度条加载安装动画.docx》由会员分享,可在线阅读,更多相关《iOS 进度条加载安装动画.docx(13页珍藏版)》请在冰豆网上搜索。

iOS 进度条加载安装动画.docx

iOS进度条加载安装动画

iOS进度条、加载、安装动画

下面贴上代码:

控制器ViewController:

#import

@interfaceViewController:

UIViewController

@end

/***---------------分割线---------------***/

#import"ViewController.h"

#import"HWWaveView.h"

#import"HWCircleView.h"

#import"HWProgressView.h"

#import"HWInstallView.h"

@interfaceViewController()

@property(nonatomic,strong)NSTimer*timer;

@property(nonatomic,weak)HWWaveView*waveView;

@property(nonatomic,weak)HWCircleView*circleView;

@property(nonatomic,weak)HWProgressView*progressView;

@property(nonatomic,weak)HWInstallView*installView;

@end

@implementationViewController

-(void)viewDidLoad{

[superviewDidLoad];

//创建控件

[selfcreatControl];

//添加定时器

[selfaddTimer];

}

-(void)creatControl

{

//波浪

HWWaveView*waveView=[[HWWaveViewalloc]initWithFrame:

CGRectMake(30,100,150,150)];

[self.viewaddSubview:

waveView];

self.waveView=waveView;

//圆圈

HWCircleView*circleView=[[HWCircleViewalloc]initWithFrame:

CGRectMake(220,100,150,150)];

[self.viewaddSubview:

circleView];

self.circleView=circleView;

//进度条

HWProgressView*progressView=[[HWProgressViewalloc]initWithFrame:

CGRectMake(30,365,150,20)];

[self.viewaddSubview:

progressView];

self.progressView=progressView;

//加载安装效果

HWInstallView*installView=[[HWInstallViewalloc]initWithFrame:

CGRectMake(220,300,150,150)];

[self.viewaddSubview:

installView];

self.installView=installView;

}

-(void)addTimer

{

_timer=[NSTimerscheduledTimerWithTimeInterval:

0.2ftarget:

selfselector:

@selector(timerAction)userInfo:

nilrepeats:

YES];

[[NSRunLoopmainRunLoop]addTimer:

_timerforMode:

NSRunLoopCommonModes];

}

-(void)timerAction

{

_waveView.progress+=0.01;

_circleView.progress+=0.01;

_progressView.progress+=0.01;

_installView.progress+=0.01;

if(_waveView.progress>=1){

[selfremoveTimer];

NSLog(@"完成");

}

}

-(void)removeTimer

{

[_timerinvalidate];

_timer=nil;

}

@end

波浪HWWaveView:

#import

@interfaceHWWaveView:

UIView

@property(nonatomic,assign)CGFloatprogress;

@end

/***---------------分割线---------------***/

#import"HWWaveView.h"

#defineKHWWaveFillColor[UIColorgroupTableViewBackgroundColor]//填充颜色

#defineKHWWaveTopColor[UIColorcolorWithRed:

0/255.0green:

191/255.0blue:

255/255.0alpha:

1.0f]//前面波浪颜色

#defineKHWWaveBottomColor[UIColorcolorWithRed:

0/255.0green:

191/255.0blue:

255/255.0alpha:

0.4f]//后面波浪颜色

@interfaceHWWaveView()

@property(nonatomic,strong)CADisplayLink*displayLink;

@property(nonatomic,assign)CGFloatwave_amplitude;//振幅a(y=asin(wx+φ)+k)

@property(nonatomic,assign)CGFloatwave_cycle;//周期w

@property(nonatomic,assign)CGFloatwave_h_distance;//两个波水平之间偏移

@property(nonatomic,assign)CGFloatwave_v_distance;//两个波竖直之间偏移

@property(nonatomic,assign)CGFloatwave_scale;//水波速率

@property(nonatomic,assign)CGFloatwave_offsety;//波峰所在位置的y坐标

@property(nonatomic,assign)CGFloatwave_move_width;//移动的距离,配合速率设置_

@property(nonatomic,assign)CGFloatwave_offsetx;//偏移

@property(nonatomic,assign)CGFloatoffsety_scale;//上升的速度

@end

@implementationHWWaveView

-(instancetype)initWithFrame:

(CGRect)frame

{

if(self=[superinitWithFrame:

frame]){

self.backgroundColor=[UIColorclearColor];

//初始化信息

[selfinitInfo];

}

returnself;

}

-(void)initInfo

{

//进度

_progress=0;

//振幅

_wave_amplitude=self.frame.size.height/25;

//周期

_wave_cycle=2*M_PI/(self.frame.size.width*0.9);

//两个波水平之间偏移

_wave_h_distance=2*M_PI/_wave_cycle*0.6;

//两个波竖直之间偏移

_wave_v_distance=_wave_amplitude*0.4;

//移动的距离,配合速率设置

_wave_move_width=0.5;

//水波速率

_wave_scale=0.4;

//上升的速度

_offsety_scale=0.1;

//波峰所在位置的y坐标,刚开始的时候_wave_offsety是最大值

_wave_offsety=(1-_progress)*(self.frame.size.height+2*_wave_amplitude);

[selfaddDisplayLinkAction];

}

-(void)addDisplayLinkAction

{

_displayLink=[CADisplayLinkdisplayLinkWithTarget:

selfselector:

@selector(displayLinkAction)];

[_displayLinkaddToRunLoop:

[NSRunLoopmainRunLoop]forMode:

NSRunLoopCommonModes];

}

-(void)displayLinkAction

{

_wave_offsetx+=_wave_move_width*_wave_scale;

//完成

if(_wave_offsety<=0.01)[selfremoveDisplayLinkAction];

[selfsetNeedsDisplay];

}

-(void)removeDisplayLinkAction

{

[_displayLinkinvalidate];

_displayLink=nil;

}

-(void)drawRect:

(CGRect)rect

{

UIBezierPath*path=[UIBezierPathbezierPathWithOvalInRect:

rect];

[KHWWaveFillColorsetFill];

[pathfill];

[pathaddClip];

//绘制两个波形图

[selfdrawWaveColor:

KHWWaveTopColoroffsetx:

0offsety:

0];

[selfdrawWaveColor:

KHWWaveBottomColoroffsetx:

_wave_h_distanceoffsety:

_wave_v_distance];

}

-(void)drawWaveColor:

(UIColor*)coloroffsetx:

(CGFloat)offsetxoffsety:

(CGFloat)offsety

{

//波浪动画,进度的实际操作范围是,多加上两个振幅的高度,到达设置进度的位置y

CGFloatend_offY=(1-_progress)*(self.frame.size.height+2*_wave_amplitude);

if(_wave_offsety!

=end_offY){

if(end_offY<_wave_offsety){

_wave_offsety=MAX(_wave_offsety-=(_wave_offsety-end_offY)*_offsety_scale,end_offY);

}lse{

_wave_offsety=MIN(_wave_offsety+=(end_offY-_wave_offsety)*_offsety_scale,end_offY);

}

}

UIBezierPath*wavePath=[UIBezierPathbezierPath];

for(floatnext_x=0.f;next_x<=self.frame.size.width;next_x++){

//正弦函数,绘制波形

CGFloatnext_y=_wave_amplitude*sin(_wave_cycle*next_x+_wave_offsetx+offsetx/self.bounds.size.width*2*M_PI)+_wave_offsety+offsety;

if(next_x==0){

[wavePathmoveToPoint:

CGPointMake(next_x,next_y-_wave_amplitude)];

}else{

[wavePathaddLineToPoint:

CGPointMake(next_x,next_y-_wave_amplitude)];

}

}

[wavePathaddLineToPoint:

CGPointMake(self.frame.size.width,self.frame.size.height)];

[wavePathaddLineToPoint:

CGPointMake(0,self.bounds.size.height)];

[colorset];

[wavePathfill];

}

@end

圆圈HWCircleView:

#import

@interfaceHWCircleView:

UIView

@property(nonatomic,assign)CGFloatprogress;

@end

/***---------------分割线---------------***/

#import"HWCircleView.h"

#defineKHWCircleLineWidth10.0f

#defineKHWCircleFont[UIFontboldSystemFontOfSize:

26.0f]

#defineKHWCircleColor[UIColorcolorWithRed:

0/255.0green:

191/255.0blue:

255/255.0alpha:

1]

@interfaceHWCircleView()

@property(nonatomic,weak)UILabel*cLabel;

@end

@implementationHWCircleView

-(instancetype)initWithFrame:

(CGRect)frame

{

if(self=[superinitWithFrame:

frame]){

self.backgroundColor=[UIColorclearColor];

//百分比标签

UILabel*cLabel=[[UILabelalloc]initWithFrame:

self.bounds];

cLabel.font=KHWCircleFont;

cLabel.textColor=KHWCircleColor;

cLabel.textAlignment=NSTextAlignmentCenter;

[selfaddSubview:

cLabel];

self.cLabel=cLabel;

}

returnself;

}

-(void)setProgress:

(CGFloat)progress

{

_progress=progress;

_cLabel.text=[NSStringstringWithFormat:

@"%d%%",(int)floor(progress*100)];

[selfsetNeedsDisplay];

}

-(void)drawRect:

(CGRect)rect

{

//路径

UIBezierPath*path=[[UIBezierPathalloc]init];

//线宽

path.lineWidth=KHWCircleLineWidth;

//颜色

[KHWCircleColorset];

//拐角

path.lineCapStyle=kCGLineCapRound;

path.lineJoinStyle=kCGLineJoinRound;

//半径

CGFloatradius=(MIN(rect.size.width,rect.size.height)-KHWCircleLineWidth)*0.5;

//画弧(参数:

中心、半径、起始角度(3点钟方向为0)、结束角度、是否顺时针)

[thaddArcWithCenter:

(CGPoint){rect.size.width*0.5,rect.size.height*0.5}radius:

radiusstartAngle:

M_PI*1.5endAngle:

M_PI*1.5+M_PI*2*_progressclockwise:

YES];

//连线

[pathstroke];

}

@end

进度条HWProgressView:

#import

@interfaceHWProgressView:

UIView

@property(nonatomic,assign)CGFloatprogress;

@end

/***---------------分割线---------------***/

#import"HWProgressView.h"

#defineKProgressBorderWidth2.0f

#defineKProgressPadding1.0f

#defineKProgressColor[UIColorcolorWithRed:

0/255.0green:

191/255.0blue:

255/255.0alpha:

1]

@interfaceHWProgressView()

@property(nonatomic,weak)UIView*tView;

@end

@implementationHWProgressView

-(instancetype)initWithFrame:

(CGRect)frame

{

if(self=[superinitWithFrame:

frame]){

//边框

UIView*borderView=[[UIViewalloc]initWithFrame:

self.bounds];

borderView.layer.cornerRadius=self.bounds.size.height*0.5;

borderView.layer.masksToBounds=YES;

borderView.backgroundColor=[UIColorwhiteColor];

borderView.layer.borderColor=[KProgressColorCGColor];

borderView.layer.borderWidth=KProgressBorderWidth;

[selfaddSubview:

borderView];

//进度

UIView*tView=[[UIViewalloc]init];

tView.backgroundColor=KProgressColor;

tView.layer.cornerRadius=(self.bounds.size.height-(KProgressBorderWidth+KProgressPadding)*2)*0.5;

tView.layer.masksToBounds=YES;

[selfaddSubview:

tView];

self.tView=tView;

}

returnself;

}

-(void)setProgress:

(CGFloat)progress

{

_progress=progress;

CGFloatmargin=KProgressBorderWidth+KProgressPadding;

CGFloatmaxWidth=self.bounds.size.width-margin*2;

CGFloatheigth=self.bounds.size.height-margin*2;

_tView.frame=CGRectMake(margin,margin,maxWidth*progress,heigth);

}

@end

加载安装效果HWInstallView:

#import

@interfaceHWInstallView:

UIView

@property(nonatomic,assign)CGFloatprogress;

@end

/***---------------分割线---------------***/

#import"HWInstallView.h"

#defineKHWInstallViewMargin10

#defineKHWInstallColor[UIColorcolorWithRed:

0/255.0green:

191/255.0blue:

255/255.0alpha:

1]

@implementationHWInstallView

-(instancetype)initWithFrame:

(CGRect)frame

{

if(self=[superinitWithFrame:

frame]){

self.backgroundColor=[UIColorclearColor];

}

returnself;

}

-(void)setProgress:

(CGFloat)progress

{

_progress=progress;

[selfsetNeedsDisplay];

}

-(void)drawRect:

(CGRect)rect

{

CGContextRefcontext=UIGraphicsGetCurrentContex

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1