iOS 進(jìn)度條、加載、安裝動(dòng)畫_第1頁(yè)
iOS 進(jìn)度條、加載、安裝動(dòng)畫_第2頁(yè)
iOS 進(jìn)度條、加載、安裝動(dòng)畫_第3頁(yè)
iOS 進(jìn)度條、加載、安裝動(dòng)畫_第4頁(yè)
iOS 進(jìn)度條、加載、安裝動(dòng)畫_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、iOS 進(jìn)度條、加載、安裝動(dòng)畫下面貼上代碼:控制器ViewController:#import <UIKit/UIKit.h>interface ViewController : UIViewControllerend/* -分割線- */#import "ViewController.h"#import "HWWaveView.h"#import "HWCircleView.h"#import "HWProgressView.h"#import "HWInstallView.h"i

2、nterface ViewController ()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;endimplementation Vi

3、ewController- (void)viewDidLoad super viewDidLoad; /創(chuàng)建控件 self creatControl; /添加定時(shí)器 self addTimer;- (void)creatControl /波浪 HWWaveView *waveView = HWWaveView alloc initWithFrame:CGRectMake(30, 100, 150, 150); self.view addSubview:waveView; self.waveView = waveView; /圓圈 HWCircleView *circleView = HWCir

4、cleView alloc initWithFrame:CGRectMake(220, 100, 150, 150); self.view addSubview:circleView; self.circleView = circleView; /進(jìn)度條 HWProgressView *progressView = HWProgressView alloc initWithFrame:CGRectMake(30, 365, 150, 20); self.view addSubview:progressView; gressView = progressView; /加載安裝效果

5、 HWInstallView *installView = HWInstallView alloc initWithFrame:CGRectMake(220, 300, 150, 150); self.view addSubview:installView; self.installView = installView;- (void)addTimer _timer = NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:selector(timerAction) userInfo:nil repeats:YES;

6、NSRunLoop mainRunLoop addTimer:_timer forMode:NSRunLoopCommonModes;- (void)timerAction _waveVgress += 0.01; _circleVgress += 0.01; _progressVgress += 0.01; _installVgress += 0.01; if (_waveVgress >= 1) self removeTimer; NSLog("完成"); - (void)removeTimer

7、 _timer invalidate; _timer = nil;end波浪HWWaveView:#import <UIKit/UIKit.h>interface HWWaveView : UIViewproperty (nonatomic, assign) CGFloat progress;end/* -分割線- */#import "HWWaveView.h"#define KHWWaveFillColor UIColor groupTableViewBackgroundColor /填充顏色#define KHWWaveTopColor UIColor c

8、olorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1.0f /前面波浪顏色#define KHWWaveBottomColor UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:0.4f /后面波浪顏色interface HWWaveView ()property (nonatomic, strong) CADisplayLink *displayLink;property (nonatomic, assign) CGFloat wave_ampli

9、tude;/振幅a(y = asin(wx+) + k)property (nonatomic, assign) CGFloat wave_cycle;/周期wproperty (nonatomic, assign) CGFloat wave_h_distance;/兩個(gè)波水平之間偏移property (nonatomic, assign) CGFloat wave_v_distance;/兩個(gè)波豎直之間偏移property (nonatomic, assign) CGFloat wave_scale;/水波速率property (nonatomic, assign) CGFloat wave

10、_offsety;/波峰所在位置的y坐標(biāo)property (nonatomic, assign) CGFloat wave_move_width;/移動(dòng)的距離,配合速率設(shè)置property (nonatomic, assign) CGFloat wave_offsetx;/偏移property (nonatomic, assign) CGFloat offsety_scale;/上升的速度endimplementation HWWaveView- (instancetype)initWithFrame:(CGRect)frame if (self = super initWithFrame:f

11、rame) self.backgroundColor = UIColor clearColor; /初始化信息 self initInfo; return self;- (void)initInfo /進(jìn)度 _progress = 0; /振幅 _wave_amplitude = self.frame.size.height / 25; /周期 _wave_cycle = 2 * M_PI / (self.frame.size.width * 0.9); /兩個(gè)波水平之間偏移 _wave_h_distance = 2 * M_PI / _wave_cycle * 0.6; /兩個(gè)波豎直之間偏移

12、 _wave_v_distance = _wave_amplitude * 0.4; /移動(dòng)的距離,配合速率設(shè)置 _wave_move_width = 0.5; /水波速率 _wave_scale = 0.4; /上升的速度 _offsety_scale = 0.1; /波峰所在位置的y坐標(biāo),剛開始的時(shí)候_wave_offsety是最大值 _wave_offsety = (1 - _progress) * (self.frame.size.height + 2 * _wave_amplitude); self addDisplayLinkAction;- (void)addDisplayLin

13、kAction _displayLink=CADisplayLinkdisplayLinkWithTarget:self selector:selector(displayLinkAction); _displayLinkaddToRunLoop:NSRunLoopmainRunLoop forMode:NSRunLoopCommonModes;- (void)displayLinkAction _wave_offsetx += _wave_move_width * _wave_scale; /完成 if (_wave_offsety <= 0.01) self removeDispla

14、yLinkAction; self setNeedsDisplay;- (void)removeDisplayLinkAction _displayLink invalidate; _displayLink = nil;- (void)drawRect:(CGRect)rect UIBezierPath *path = UIBezierPath bezierPathWithOvalInRect:rect; KHWWaveFillColor setFill; path fill; path addClip; /繪制兩個(gè)波形圖 self drawWaveColor:KHWWaveTopColor

15、offsetx:0 offsety:0; selfdrawWaveColor:KHWWaveBottomColoroffsetx:_wave_h_distance offsety:_wave_v_distance;- (void)drawWaveColor:(UIColor *)color offsetx:(CGFloat)offsetx offsety:(CGFloat)offsety /波浪動(dòng)畫,進(jìn)度的實(shí)際操作范圍是,多加上兩個(gè)振幅的高度,到達(dá)設(shè)置進(jìn)度的位置y CGFloat end_offY = (1 - _progress) * (self.frame.size.height + 2

16、* _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 = UIBezier

17、Path bezierPath; for (float next_x = 0.f; next_x <= self.frame.size.width; next_x +) /正弦函數(shù),繪制波形 CGFloat next_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) wavePath moveToPoint:CGPointMake(ne

18、xt_x, next_y - _wave_amplitude); else wavePath addLineToPoint:CGPointMake(next_x, next_y - _wave_amplitude); wavePath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height); wavePath addLineToPoint:CGPointMake(0, self.bounds.size.height); color set; wavePath fill;end圓圈HWCircleView

19、:#import <UIKit/UIKit.h>interface HWCircleView : UIViewproperty (nonatomic, assign) CGFloat progress;end/* -分割線- */#import "HWCircleView.h"#define KHWCircleLineWidth 10.0f#define KHWCircleFont UIFont boldSystemFontOfSize:26.0f#define KHWCircleColor UIColor colorWithRed:0/255.0 green:

20、191/255.0 blue:255/255.0 alpha:1interface HWCircleView ()property (nonatomic, weak) UILabel *cLabel;endimplementation HWCircleView- (instancetype)initWithFrame:(CGRect)frame if (self = super initWithFrame:frame) self.backgroundColor = UIColor clearColor; /百分比標(biāo)簽 UILabel *cLabel = UILabel alloc initWi

21、thFrame:self.bounds; cLabel.font = KHWCircleFont; cLabel.textColor = KHWCircleColor; cLabel.textAlignment = NSTextAlignmentCenter; self addSubview:cLabel; self.cLabel = cLabel; return self;- (void)setProgress:(CGFloat)progress _progress = progress; _cLabel.text = NSString stringWithFormat:"%d%&

22、quot;, (int)floor(progress * 100); self setNeedsDisplay;- (void)drawRect:(CGRect)rect /路徑 UIBezierPath *path = UIBezierPath alloc init; /線寬 path.lineWidth = KHWCircleLineWidth; /顏色 KHWCircleColor set; /拐角 path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineJoinRound; /半徑 CGFloat radius

23、= (MIN(rect.size.width, rect.size.height) - KHWCircleLineWidth) * 0.5; /畫弧(參數(shù):中心、半徑、起始角度(3點(diǎn)鐘方向?yàn)?)、結(jié)束角度、是否順時(shí)針) thaddArcWithCenter:(CGPoint)rect.size.width * 0.5, rect.size.height * 0.5 radius:radius startAngle:M_PI * 1.5 endAngle:M_PI * 1.5 + M_PI * 2 * _progress clockwise:YES; /連線 path stroke;end進(jìn)度條

24、HWProgressView:#import <UIKit/UIKit.h>interface HWProgressView : UIViewproperty (nonatomic, assign) CGFloat progress;end/* -分割線- */#import "HWProgressView.h"#define KProgressBorderWidth 2.0f#define KProgressPadding 1.0f#define KProgressColor UIColor colorWithRed:0/255.0 green:191/255

25、.0 blue:255/255.0 alpha:1interface HWProgressView ()property (nonatomic, weak) UIView *tView;endimplementation HWProgressView- (instancetype)initWithFrame:(CGRect)frame if (self = super initWithFrame:frame) /邊框 UIView *borderView = UIView alloc initWithFrame:self.bounds; borderView.layer.cornerRadiu

26、s = self.bounds.size.height * 0.5; borderView.layer.masksToBounds = YES; borderView.backgroundColor = UIColor whiteColor; borderView.layer.borderColor = KProgressColor CGColor; borderView.layer.borderWidth = KProgressBorderWidth; self addSubview:borderView; /進(jìn)度 UIView *tView = UIView alloc init; tVi

27、ew.backgroundColor = KProgressColor; tView.layer.cornerRadius = (self.bounds.size.height - (KProgressBorderWidth + KProgressPadding) * 2) * 0.5; tView.layer.masksToBounds = YES; self addSubview:tView; self.tView = tView; return self;- (void)setProgress:(CGFloat)progress _progress = progress; CGFloat

28、 margin = KProgressBorderWidth + KProgressPadding; CGFloat maxWidth = self.bounds.size.width - margin * 2; CGFloat heigth = self.bounds.size.height - margin * 2; _tView.frame = CGRectMake(margin, margin, maxWidth * progress, heigth);end加載安裝效果HWInstallView:#import <UIKit/UIKit.h>interface HWIns

29、tallView : UIViewproperty (nonatomic, assign) CGFloat progress;end/* -分割線- */#import "HWInstallView.h"#define KHWInstallViewMargin 10#define KHWInstallColor UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1implementation HWInstallView- (instancetype)initWithFrame:(CGRect)frame if (se

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論