亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

iOS 進度條、加載、安裝動畫的簡單實現

2020-07-26 02:54:38
字體:
來源:轉載
供稿:網友

首先看一下效果圖:

下面貼上代碼:

控制器ViewController:

#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end /*** ---------------分割線--------------- ***/ #import "ViewController.h" #import "HWWaveView.h" #import "HWCircleView.h" #import "HWProgressView.h" #import "HWInstallView.h" @interface 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; @end @implementation ViewController - (void)viewDidLoad {  [super viewDidLoad];  //創建控件  [self creatControl];  //添加定時器  [self addTimer]; } - (void)creatControl {  //波浪  HWWaveView *waveView = [[HWWaveView alloc] initWithFrame:CGRectMake(30, 100, 150, 150)];  [self.view addSubview:waveView];  self.waveView = waveView;  //圓圈  HWCircleView *circleView = [[HWCircleView alloc] initWithFrame:CGRectMake(220, 100, 150, 150)];  [self.view addSubview:circleView];  self.circleView = circleView;  //進度條  HWProgressView *progressView = [[HWProgressView alloc] initWithFrame:CGRectMake(30, 365, 150, 20)];  [self.view addSubview:progressView];  self.progressView = progressView;  //加載安裝效果  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];  [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; } - (void)timerAction {  _waveView.progress += 0.01;  _circleView.progress += 0.01;  _progressView.progress += 0.01;  _installView.progress += 0.01;  if (_waveView.progress >= 1) {   [self removeTimer];   NSLog(@"完成");  } } - (void)removeTimer {  [_timer invalidate];  _timer = nil; } @end 波浪HWWaveView:[objc] view plain copy 在CODE上查看代碼片派生到我的代碼片#import <UIKit/UIKit.h> @interface HWWaveView : UIView @property (nonatomic, assign) CGFloat progress; @end /*** ---------------分割線--------------- ***/ #import "HWWaveView.h" #define KHWWaveFillColor [UIColor groupTableViewBackgroundColor] //填充顏色 #define KHWWaveTopColor [UIColor colorWithRed: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_amplitude;//振幅a(y = asin(wx+φ) + k) @property (nonatomic, assign) CGFloat wave_cycle;//周期w @property (nonatomic, assign) CGFloat wave_h_distance;//兩個波水平之間偏移 @property (nonatomic, assign) CGFloat wave_v_distance;//兩個波豎直之間偏移 @property (nonatomic, assign) CGFloat wave_scale;//水波速率 @property (nonatomic, assign) CGFloat wave_offsety;//波峰所在位置的y坐標 @property (nonatomic, assign) CGFloat wave_move_width;//移動的距離,配合速率設置 @property (nonatomic, assign) CGFloat wave_offsetx;//偏移 @property (nonatomic, assign) CGFloat offsety_scale;//上升的速度 @end @implementation HWWaveView - (instancetype)initWithFrame:(CGRect)frame {  if (self = [super initWithFrame:frame]) {   self.backgroundColor = [UIColor clearColor];   //初始化信息   [self initInfo];  }  return self; } - (void)initInfo {  //進度  _progress = 0;  //振幅  _wave_amplitude = self.frame.size.height / 25;  //周期  _wave_cycle = 22 * M_PI / (self.frame.size.width * 0.9);  //兩個波水平之間偏移  _wave_h_distance = 22 * 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 + 22 * _wave_amplitude);  [self addDisplayLinkAction]; } - (void)addDisplayLinkAction {  _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkAction)];  [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; } - (void)displayLinkAction {  _wave_offsetx += _wave_move_width * _wave_scale;  //完成  if (_wave_offsety <= 0.01) [self removeDisplayLinkAction];  [self setNeedsDisplay]; } - (void)removeDisplayLinkAction {  [_displayLink invalidate];  _displayLink = nil; } - (void)drawRect:(CGRect)rect {  UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];  [KHWWaveFillColor setFill];  [path fill];  [path addClip];  //繪制兩個波形圖  [self drawWaveColor:KHWWaveTopColor offsetx:0 offsety:0];  [self drawWaveColor:KHWWaveBottomColor offsetx:_wave_h_distance offsety:_wave_v_distance]; } - (void)drawWaveColor:(UIColor *)color offsetx:(CGFloat)offsetx offsety:(CGFloat)offsety {  //波浪動畫,進度的實際操作范圍是,多加上兩個振幅的高度,到達設置進度的位置y  CGFloat end_offY = (1 - _progress) * (self.frame.size.height + 22 * _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);   }else {    _wave_offsety = MIN(_wave_offsety += (end_offY - _wave_offsety) * _offsety_scale, end_offY);   }  }  UIBezierPath *wavePath = [UIBezierPath bezierPath];  for (float next_x = 0.f; next_x <= self.frame.size.width; next_x ++) {   //正弦函數,繪制波形   CGFloat next_y = _wave_amplitude * sin(_wave_cycle * next_x + _wave_offsetx + offsetx / self.bounds.size.width * 22 * M_PI) + _wave_offsety + offsety;   if (next_x == 0) {    [wavePath moveToPoint:CGPointMake(next_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:[objc] view plain copy 在CODE上查看代碼片派生到我的代碼片#import <UIKit/UIKit.h> @interface HWCircleView : UIView @property (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:191/255.0 blue:255/255.0 alpha:1] @interface HWCircleView () @property (nonatomic, weak) UILabel *cLabel; @end @implementation HWCircleView - (instancetype)initWithFrame:(CGRect)frame {  if (self = [super initWithFrame:frame]) {   self.backgroundColor = [UIColor clearColor];   //百分比標簽   UILabel *cLabel = [[UILabel alloc] initWithFrame: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%%", (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 = (MIN(rect.size.width, rect.size.height) - KHWCircleLineWidth) * 0.5;  //畫?。▍担褐行?、半徑、起始角度(3點鐘方向為0)、結束角度、是否順時針)  [path addArcWithCenter:(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 * 22 * _progress clockwise:YES];  //連線  [path stroke]; } @end 進度條HWProgressView:[objc] view plain copy 在CODE上查看代碼片派生到我的代碼片#import <UIKit/UIKit.h> @interface HWProgressView : UIView @property (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.0 blue:255/255.0 alpha:1] @interface HWProgressView () @property (nonatomic, weak) UIView *tView; @end @implementation HWProgressView - (instancetype)initWithFrame:(CGRect)frame {  if (self = [super initWithFrame:frame]) {   //邊框   UIView *borderView = [[UIView alloc] initWithFrame:self.bounds];   borderView.layer.cornerRadius = 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];   //進度   UIView *tView = [[UIView alloc] init];   tView.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 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:[objc] view plain copy 在CODE上查看代碼片派生到我的代碼片#import <UIKit/UIKit.h> @interface HWInstallView : UIView @property (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:1] @implementation HWInstallView - (instancetype)initWithFrame:(CGRect)frame {  if (self = [super initWithFrame:frame]) {   self.backgroundColor = [UIColor clearColor];  }  return self; } - (void)setProgress:(CGFloat)progress {  _progress = progress;  [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect {  CGContextRef context = UIGraphicsGetCurrentContext();  CGFloat xCenter = rect.size.width * 0.5;  CGFloat yCenter = rect.size.height * 0.5;  CGFloat radius = MIN(rect.size.width, rect.size.height) * 0.5 - KHWInstallViewMargin;  //背景遮罩  [KHWInstallColor set];  CGFloat lineW = MAX(rect.size.width, rect.size.height) * 0.5;  CGContextSetLineWidth(context, lineW);  CGContextAddArc(context, xCenter, yCenter, radius + lineW * 0.5 + 5, 0, M_PI * 2, 1);  CGContextStrokePath(context);  //進程圓  CGContextSetLineWidth(context, 1);  CGContextMoveToPoint(context, xCenter, yCenter);  CGContextAddLineToPoint(context, xCenter, 0);  CGFloat endAngle = - M_PI * 0.5 + _progress * M_PI * 2 + 0.001;  CGContextAddArc(context, xCenter, yCenter, radius, - M_PI * 0.5, endAngle, 1);  CGContextFillPath(context); } @end 

以上所述是小編給大家介紹的iOS 進度條、加載、安裝動畫的簡單實現,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
69国产精品成人在线播放| 97在线看免费观看视频在线观看| 欧美日韩精品国产| 久久色免费在线视频| 91免费观看网站| 亚洲黄色www网站| 国产v综合v亚洲欧美久久| 欧美激情极品视频| 国产精品日日做人人爱| 中文字幕亚洲欧美日韩2019| 美女扒开尿口让男人操亚洲视频网站| 亚洲国产欧美久久| 久久精品色欧美aⅴ一区二区| 91美女福利视频高清| 国产精品视频999| 亚洲国产精品yw在线观看| 91探花福利精品国产自产在线| 91精品国产高清| 国产精品网址在线| 亚洲最大中文字幕| 亚洲成人教育av| 国内偷自视频区视频综合| 在线播放日韩欧美| 欧美日本亚洲视频| 成人久久久久爱| 欧美丰满片xxx777| 国产欧美在线观看| 久久亚洲影音av资源网| 日韩最新av在线| 国语自产精品视频在线看抢先版图片| 日韩69视频在线观看| 992tv在线成人免费观看| 欧美日韩国产中字| 亚洲欧美成人精品| 国产精品成人av性教育| 欧美电影免费观看电视剧大全| 国产欧美日韩精品在线观看| 国产精品羞羞答答| 日韩欧美国产成人| 国产精品黄视频| 亚洲精品aⅴ中文字幕乱码| 91天堂在线观看| 亚洲tv在线观看| 亚洲香蕉伊综合在人在线视看| 国产色视频一区| 中文字幕在线看视频国产欧美| 国产精品久久9| 91精品久久久久久久久久入口| 日韩精品高清视频| 91香蕉电影院| 久久九九国产精品怡红院| 欧美成人免费网| 欧美国产极速在线| 亚洲精品欧美日韩专区| 欧美日韩激情美女| 久久不射热爱视频精品| 亚洲男人天堂网站| 日韩男女性生活视频| 青青草原一区二区| 久久亚洲精品国产亚洲老地址| 伊人成人开心激情综合网| 亚洲欧洲视频在线| 国产日韩欧美自拍| 精品国产一区二区三区久久狼5月| 91久久精品国产91性色| 欧美极品少妇xxxxⅹ免费视频| 亚洲欧美激情在线视频| 国产精品私拍pans大尺度在线| 中文字幕亚洲综合久久| 欧美性猛交xxxx乱大交极品| 欧美激情在线狂野欧美精品| 红桃av永久久久| 久久av红桃一区二区小说| 国内精品久久久久久影视8| 91精品在线国产| 亚洲精品久久在线| 国产精品久久久久久久久| 亚洲第五色综合网| 美女扒开尿口让男人操亚洲视频网站| 国产精品成人观看视频国产奇米| 98视频在线噜噜噜国产| 亚洲成人av资源网| 国产精品劲爆视频| 欧美性猛交99久久久久99按摩| 亚洲91精品在线| 91高清视频在线免费观看| 亚洲国产精品va在线看黑人动漫| 精品露脸国产偷人在视频| 尤物yw午夜国产精品视频| 国产高清视频一区三区| 日韩免费黄色av| 91丨九色丨国产在线| 91高潮在线观看| 欧美电影《睫毛膏》| 456亚洲影院| 日韩精品在线电影| 欧美日韩国产色| 国产aⅴ夜夜欢一区二区三区| 亚洲片av在线| 欧美噜噜久久久xxx| 一区二区三区国产视频| 日产精品99久久久久久| 亚洲欧美在线x视频| 中文字幕亚洲一区二区三区五十路| 97av在线视频免费播放| 日韩av最新在线观看| 国产日韩换脸av一区在线观看| 美女国内精品自产拍在线播放| 国产97在线|亚洲| 日韩精品日韩在线观看| 欧美特黄级在线| 欧美日韩成人在线视频| 欧美激情三级免费| 久久久精品电影| 久久精品99国产精品酒店日本| 久久精品国产亚洲精品2020| 国产手机视频精品| 亚洲欧美日韩视频一区| 精品女同一区二区三区在线播放| 日韩有码在线播放| 精品亚洲va在线va天堂资源站| 91在线观看免费观看| 97视频在线观看播放| 成人精品一区二区三区电影免费| 欧美激情在线观看| 91麻豆国产精品| 亚洲最大的免费| 亚洲欧美日本另类| 久久五月天综合| 色偷偷噜噜噜亚洲男人| 久久电影一区二区| 日韩视频免费在线观看| 亚洲香蕉av在线一区二区三区| 欧美日韩国产一区中文午夜| 欧美精品在线第一页| 国产精品一区二区三区毛片淫片| 日韩av在线免费播放| 亚洲精品第一国产综合精品| 国产午夜精品美女视频明星a级| 中文字幕欧美日韩在线| 国产98色在线| 亚洲女人天堂色在线7777| 亚洲欧美日韩在线高清直播| 欧美激情2020午夜免费观看| 综合136福利视频在线| 欧美日韩中文字幕在线视频| 日韩一区av在线| 日韩综合中文字幕| 欧洲亚洲免费视频| 亚洲精品自在久久| 日韩精品亚洲元码| 91久热免费在线视频| 国产精品九九久久久久久久| 久久精品一本久久99精品| 亚洲欧洲第一视频| 92版电视剧仙鹤神针在线观看| 久久影视电视剧凤归四时歌| 奇米四色中文综合久久| 在线观看国产精品91| 91精品国产高清| 九九精品在线观看| 国外成人免费在线播放| 91老司机精品视频| 欧美在线观看网址综合|