最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS 進度條、加載、安裝動畫的簡單實現(xiàn)

 更新時間:2017年03月06日 17:12:04   作者:hero_wqb  
這篇文章主要介紹了iOS 進度條、加載、安裝動畫的簡單實現(xiàn),非常不錯,具有參考借鑒價值,需要的朋友可以參考下

首先看一下效果圖:

下面貼上代碼:

控制器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]; 
 //創(chuàng)建控件 
 [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 ++) { 
  //正弦函數(shù),繪制波形 
  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; 
 //畫弧(參數(shù):中心、半徑、起始角度(3點鐘方向為0)、結(jié)束角度、是否順時針) 
 [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 進度條、加載、安裝動畫的簡單實現(xiàn),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • 12個iOS技術面試題及答案總結(jié)

    12個iOS技術面試題及答案總結(jié)

    這篇文章給大家總結(jié)了在iOS面試的時候可能會遇到的12個技術面試題,以及這些面試題但答案,這些答案只是給大家一些參考,大家可以再結(jié)合自己理解進行回答,有需要的朋友們下面來一起看看吧。
    2016-09-09
  • 淺析iOS中視頻播放的幾種方案

    淺析iOS中視頻播放的幾種方案

    還記得剛學iOS的時候嗎?那個時候驚訝于各種牛逼的功能只需要幾句簡單的代碼就可以完成。視頻播放也是這樣,IOS中視頻播放有好幾種方式,這篇文章就給大家整理這幾種方案優(yōu)缺點與實現(xiàn)過程。
    2016-08-08
  • iOS 禁止按鈕在一定時間內(nèi)連續(xù)點擊

    iOS 禁止按鈕在一定時間內(nèi)連續(xù)點擊

    本文主要介紹了iOS中禁止按鈕在一定時間內(nèi)連續(xù)點擊的方法,具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • iOS10適配問題及解決方法 新鮮出爐!

    iOS10適配問題及解決方法 新鮮出爐!

    這篇文章主要為大家詳細介紹了iOS 10適配問題,總結(jié)了一些關于iOS10適配方面的問題,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 掃描二維碼控件的封裝iOS實現(xiàn)

    掃描二維碼控件的封裝iOS實現(xiàn)

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)掃描二維碼控件的封裝,具有一定的實用性和參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • iOS開發(fā)實戰(zhàn)之Label全方位對齊的輕松實現(xiàn)

    iOS開發(fā)實戰(zhàn)之Label全方位對齊的輕松實現(xiàn)

    這篇文章主要給大家介紹了關于iOS開發(fā)實戰(zhàn)之輕松實現(xiàn)Label全方位對齊的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-10-10
  • iOS彈幕組件LNDanmakuMaster的具體使用

    iOS彈幕組件LNDanmakuMaster的具體使用

    這篇文章主要介紹了iOS彈幕組件LNDanmakuMaster的具體使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-02-02
  • iOS實現(xiàn)動態(tài)的開屏廣告示例代碼

    iOS實現(xiàn)動態(tài)的開屏廣告示例代碼

    啟動圖是在iOS開發(fā)過程中必不可少的一個部分,很多app在啟動圖之后會有一張自定義的開屏廣告圖,但是有的時候需要讓啟動圖看起來就是一個廣告,而且還要這個廣告里面會動,iOS的啟動圖只能是靜態(tài)的,而且固定,為了實現(xiàn)看起來的動畫效果,只能進行偽造了。下面來一起看看
    2016-09-09
  • iOS左右滑動標簽頁導航的設計

    iOS左右滑動標簽頁導航的設計

    這篇文章主要為大家詳細介紹了iOS左右滑動標簽頁導航的設計思路,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • IOS中無限滾動Scrollview效果

    IOS中無限滾動Scrollview效果

    這篇文章主要為大家詳細介紹了IOS中無限滾動Scrollview效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02

最新評論

台前县| 丘北县| 泾川县| 黑水县| 宁国市| 策勒县| 商河县| 亳州市| 黄梅县| 开平市| 思茅市| 霍城县| 黄骅市| 北海市| 贡觉县| 东丽区| 迁安市| 富锦市| 河间市| 徐闻县| 女性| 临沧市| 龙江县| 乐亭县| 汨罗市| 会昌县| 黄大仙区| 天峻县| 广安市| 天台县| 共和县| 原阳县| 通河县| 元阳县| 商洛市| 嘉鱼县| 玉林市| 华池县| 泗洪县| 东方市| 哈巴河县|