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

首頁 > 系統 > iOS > 正文

IOS使用progssview仿滴滴打車圓形計時

2020-07-26 03:34:59
字體:
來源:轉載
供稿:網友

實現類似在微信中使用的滴滴打車的progressview,實現效果如圖

//// CCProgressView.h// HurricaneConsumer//// Created by wangcong on 15-3-25.// Copyright (c) 2015年 WangCong. All rights reserved.// #import <UIKit/UIKit.h>#import <QuartzCore/QuartzCore.h> /** * 動畫開始 */typedef void(^block_progress_start)(); /** * 動畫正在進行 * @param NSTimeInterval */typedef void(^block_progress_animing)(NSTimeInterval); /** * 動畫結束 */typedef void(^block_progress_stop)(); @interface CCProgressView : UIView{  NSTimeInterval _animationTime;} @property (nonatomic, strong) UILabel *centerLabel;    // 中心Label @property (nonatomic, copy) block_progress_start start;   // 動畫開始回調@property (nonatomic, copy) block_progress_animing animing; // 動畫進行@property (nonatomic, copy) block_progress_stop stop;    // 動畫結束回調 - (void) setAnimationTime:(NSTimeInterval)animationTime; - (void)startAnimation; - (void)stopAnimation; @end  //// CCProgressView.m// HurricaneConsumer//// Created by wangcong on 15-3-25.// Copyright (c) 2015年 WangCong. All rights reserved.// #import "CCProgressView.h" #define kProgressThumbWh 30 // 計時器間隔時長#define kAnimTimeInterval 0.1 /** * 圓圈layer上旋轉的layer */@interface CCProgressThumb : CALayer{  NSTimeInterval _animationTime;} @property (assign, nonatomic) double startAngle;@property (nonatomic, strong) UILabel *timeLabel;      // 顯示時間Label @end @implementation CCProgressThumb - (instancetype)init{  if ((self = [super init])) {    [self setupLayer];  }  return self;} - (void)layoutSublayers{  _timeLabel.frame = self.bounds;     [_timeLabel sizeToFit];  _timeLabel.center = CGPointMake(CGRectGetMidX(self.bounds) - _timeLabel.frame.origin.x,                  CGRectGetMidY(self.bounds) - _timeLabel.frame.origin.y);} - (void)setupLayer{  // 繪制圓  UIGraphicsBeginImageContext(CGSizeMake(kProgressThumbWh, kProgressThumbWh));  CGContextRef ctx = UIGraphicsGetCurrentContext();  CGContextSetLineWidth(ctx, 1);  CGContextSetFillColorWithColor(ctx, [UIColor lightGrayColor].CGColor);  CGContextSetStrokeColorWithColor(ctx, [UIColor lightGrayColor].CGColor);  CGContextAddEllipseInRect(ctx, CGRectMake(1, 1, kProgressThumbWh - 2, kProgressThumbWh - 2));  CGContextDrawPath(ctx, kCGPathFillStroke);  UIImage *circle = UIGraphicsGetImageFromCurrentImageContext();  UIGraphicsEndImageContext();     UIImageView *circleView = [[UIImageView alloc] initWithImage:circle];  circleView.frame = CGRectMake(0, 0, kProgressThumbWh, kProgressThumbWh);  circleView.image = circle;  [self addSublayer:circleView.layer];     _timeLabel = [[UILabel alloc] initWithFrame:self.bounds];  _timeLabel.textColor = [UIColor redColor];  _timeLabel.font = [UIFont systemFontOfSize:10];  _timeLabel.textAlignment = NSTextAlignmentCenter;  _timeLabel.text = @"00:00";  [self addSublayer:_timeLabel.layer];     _startAngle = - M_PI / 2;} - (void)setAnimationTime:(NSTimeInterval)animationTime{  _animationTime = animationTime;} - (double)calculatePercent:(NSTimeInterval)fromTime toTime:(NSTimeInterval)toTime{  double progress = 0.0f;  if ((toTime > 0) && (fromTime > 0)) {    progress = fromTime / toTime;    if ((progress * 100) > 100) {      progress = 1.0f;    }  }  return progress;} - (void)startAnimation{  CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];  pathAnimation.calculationMode = kCAAnimationPaced;  pathAnimation.fillMode = kCAFillModeForwards;  pathAnimation.removedOnCompletion = YES;  pathAnimation.duration = kAnimTimeInterval;  pathAnimation.repeatCount = 0;  pathAnimation.autoreverses = YES;     CGMutablePathRef arcPath = CGPathCreateMutable();  CGPathAddPath(arcPath, NULL, [self bezierPathFromParentLayerArcCenter]);  pathAnimation.path = arcPath;  CGPathRelease(arcPath);  [self addAnimation:pathAnimation forKey:@"position"];} /** * 根據父Layer獲取到一個移動路徑 * @return */- (CGPathRef)bezierPathFromParentLayerArcCenter{  CGFloat centerX = CGRectGetWidth(self.superlayer.frame) / 2.0;  CGFloat centerY = CGRectGetHeight(self.superlayer.frame) / 2.0;  double tmpStartAngle = _startAngle;  _startAngle = _startAngle + (2 * M_PI) * kAnimTimeInterval / _animateTime;  return [UIBezierPath bezierPathWithArcCenter:CGPointMake(centerX, centerY)                     radius:centerX                   startAngle:tmpStartAngle                    endAngle:_startAngle                    clockwise:YES].CGPath;} - (void)stopAnimation{  [self removeAllAnimations];} - (void)dealloc{  [[NSNotificationCenter defaultCenter] removeObserver:self];} @end /** * 圓圈layer */@interface CCProgress : CAShapeLayer{  NSTimeInterval _animationTime;} @property (assign, nonatomic) double initialProgress;@property (nonatomic) NSTimeInterval elapsedTime;                   //已使用時間@property (assign, nonatomic) double percent;@property (nonatomic, strong) UIColor *circleColor;@property (nonatomic, strong) CAShapeLayer *progress;@property (nonatomic, strong) CCProgressThumb *thumb;@property (nonatomic, assign) CGRect frame; @end @implementation CCProgress - (instancetype) init{  if ((self = [super init])) {    [self setupLayer];  }  return self;} - (void)layoutSublayers{  self.path = [self bezierPathWithArcCenter];  self.progress.path = self.path;     self.thumb.frame = CGRectMake((320 - kProgressThumbWh) / 2.0f, 180, kProgressThumbWh, kProgressThumbWh);  [super layoutSublayers];} - (void)setupLayer{  // 繪制圓  self.path = [self bezierPathWithArcCenter];  self.fillColor = [UIColor clearColor].CGColor;  self.strokeColor = [UIColor colorWithRed:0.86f green:0.86f blue:0.86f alpha:0.4f].CGColor;  self.lineWidth = 2;     // 添加可以變動的滾動條  self.progress = [CAShapeLayer layer];  self.progress.path = self.path;  self.progress.fillColor = [UIColor clearColor].CGColor;  self.progress.strokeColor = [UIColor whiteColor].CGColor;  self.progress.lineWidth = 4;  self.progress.lineCap = kCALineCapSquare;  self.progress.lineJoin = kCALineCapSquare;  [self addSublayer:self.progress];     // 添加可以旋轉的ThumbLayer  self.thumb = [[CCProgressThumb alloc] init];  [self addSublayer:self.thumb];} /** * 得到bezier曲線路勁 * @return */- (CGPathRef)bezierPathWithArcCenter{  CGFloat centerX = CGRectGetWidth(self.frame) / 2.0;  CGFloat centerY = CGRectGetHeight(self.frame) / 2.0;  return [UIBezierPath bezierPathWithArcCenter:CGPointMake(centerX, centerY)                     radius:centerX                   startAngle:(- M_PI / 2)                    endAngle:(3 * M_PI / 2)                    clockwise:YES].CGPath;} - (void)setCircleColor:(UIColor *)circleColor{  self.progress.strokeColor = circleColor.CGColor;} - (void)setAnimtionTime:(NSTimeInterval)animtionTime{  _animationTime = animtionTime;  [self.thumb setAnimationTime:animtionTime];} - (void)setElapsedTime:(NSTimeInterval)elapsedTime{  _initialProgress = [self calculatePercent:_elapsedTime toTime:_animationTime];  _elapsedTime = elapsedTime;     self.progress.strokeEnd = self.percent;  [self startAnimation];} - (double)percent{  _percent = [self calculatePercent:_elapsedTime toTime:_animationTime];  return _percent;} - (double)calculatePercent:(NSTimeInterval)fromTime toTime:(NSTimeInterval)toTime{  double progress = 0.0f;  if ((toTime > 0) && (fromTime > 0)) {    progress = fromTime / toTime;    if ((progress * 100) > 100) {      progress = 1.0f;    }  }  return progress;} - (void)startAnimation{  CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];  pathAnimation.duration = kAnimTimeInterval;  pathAnimation.fromValue = @(self.initialProgress);  pathAnimation.toValue = @(self.percent);  pathAnimation.removedOnCompletion = YES;  [self.progress addAnimation:pathAnimation forKey:nil];     [self.thumb startAnimation];  self.thumb.timeLabel.text = [self stringFromTimeInterval:_elapsedTime shorTime:YES];} - (void)stopAnimation{  _elapsedTime = 0;  self.progress.strokeEnd = 0.0;  [self removeAllAnimations];  [self.thumb stopAnimation];} /** * 時間格式轉換 * @param interval NSTimeInterval * @param shortTime BOOL * @return */- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval shorTime:(BOOL)shortTime{  NSInteger ti = (NSInteger)interval;  NSInteger seconds = ti % 60;  NSInteger minutes = (ti / 60) % 60;  NSInteger hours = (ti / 3600);  if (shortTime) {    return [NSString stringWithFormat:@"%02ld:%02ld", (long)hours, (long)seconds];  } else {    return [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)hours, (long)minutes, (long)seconds];  }} @end @interface CCProgressView () @property (nonatomic, strong) CCProgress *progressLayer;@property (nonatomic, strong) NSTimer *timer; @end @implementation CCProgressView - (instancetype)init{  if ((self = [super init])) {    [self setupView];  }  return self;} - (instancetype)initWithFrame:(CGRect)frame{  if ((self = [super initWithFrame:frame])) {    [self setupView];  }  return self;} - (void)layoutSubviews{  [super layoutSubviews];  self.progressLayer.frame = self.bounds;     [self.centerLabel sizeToFit];  self.centerLabel.center = CGPointMake(self.center.x - self.frame.origin.x, self.center.y- self.frame.origin.y);} - (void)setupView{  self.backgroundColor = [UIColor clearColor];  self.clipsToBounds = false;     self.progressLayer = [[CCProgress alloc] init];  self.progressLayer.frame = self.bounds;  [self.layer addSublayer:self.progressLayer];     _centerLabel = [[UILabel alloc] initWithFrame:self.bounds];  _centerLabel.font = [UIFont systemFontOfSize:18];  _centerLabel.textAlignment = NSTextAlignmentCenter;  _centerLabel.textColor = [UIColor whiteColor];  _centerLabel.text = @"已推送至 3 家";  [self.layer addSublayer:_centerLabel.layer];} - (void)setAnimationTime:(NSTimeInterval)animationTime{  _animationTime = animationTime;  [self.progressLayer setAnimtionTime:animationTime];} - (void)startAnimation{  if (!_timer) {    _timer = [NSTimer timerWithTimeInterval:kAnimTimeInterval target:self selector:@selector(doTimerSchedule) userInfo:nil repeats:YES];    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];  }  self.progressLayer.elapsedTime = 0;  if (_start) _start();} - (void)doTimerSchedule{  self.progressLayer.elapsedTime = self.progressLayer.elapsedTime + kAnimTimeInterval;;  if (_animing) _animing(self.progressLayer.elapsedTime);     if (self.progressLayer.elapsedTime >= _animationTime) {    [self stopAnimation];  }} - (void)stopAnimation{  if (_stop) _stop();  if (_timer) {    [_timer invalidate];    _timer = nil;  }  [_progressLayer stopAnimation];} @end 使用實例_progressView = [[CCProgressView alloc] initWithFrame:CGRectMake((APP_WIDTH - 240) / 2.0f, (APP_HEIGHT - 240) / 2.0f, 240, 240)];  [_progressView setAnimationTime:60];  _progressView.start = ^() {    NSLog(@"開始");  };  _progressView.animing = ^ (NSTimeInterval currentTime) {    NSLog(@"進行中");  };  __block id weakSelf = self;  _progressView.stop = ^ () {    NSLog(@"結束");    [weakSelf dismiss];  };  [self addSubview:_progressView];     [_progressView startAnimation];

以上所述就是本文的全部內容了,希望大家能夠喜歡

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产欧美va欧美va香蕉在| 国产精品日日摸夜夜添夜夜av| 日韩美女在线观看一区| 国产日韩av高清| 欧美成人精品h版在线观看| 国产成人免费av| 日韩成人黄色av| 欧美激情xxxx性bbbb| 国产精品视频大全| 国产精品欧美在线| 亚洲国产欧美一区二区丝袜黑人| 欧美日韩国产综合新一区| 性日韩欧美在线视频| 欧美日韩在线视频一区| 国产精品视频久久久久| 欧美日韩精品中文字幕| 粉嫩av一区二区三区免费野| 亚洲精品国精品久久99热| 久久久999国产| 欧美人成在线视频| 美日韩在线视频| 成人欧美一区二区三区黑人| 久久久久久亚洲精品中文字幕| 亚洲综合在线播放| 国产区亚洲区欧美区| 97avcom| 久久精品99久久久久久久久| 一区二区三区在线播放欧美| 日韩av电影免费观看高清| 91精品国产91久久久久| 日韩中文字幕在线| 国产日韩欧美在线视频观看| 欧美激情xxxxx| 秋霞成人午夜鲁丝一区二区三区| 日韩av在线影视| 国产精品亚洲аv天堂网| 欧美色另类天堂2015| 国产精品久久久久久av福利软件| 岛国视频午夜一区免费在线观看| 亚洲欧美国产高清va在线播| 亚洲91精品在线观看| 欧洲亚洲免费视频| 91av视频导航| 日韩电影中文字幕av| 欧美色另类天堂2015| 久久天天躁狠狠躁老女人| 国产精品扒开腿做爽爽爽的视频| 欧美激情一区二区久久久| 日韩欧美国产黄色| 91精品视频在线看| 日韩中文字幕免费视频| 欧美成人一区二区三区电影| 国产精品吊钟奶在线| 2021久久精品国产99国产精品| 一个色综合导航| 成人欧美在线视频| 国产亚洲精品一区二555| 中文字幕在线日韩| 国产精品久久久久77777| 日韩在线观看你懂的| 欧美黄网免费在线观看| 麻豆国产va免费精品高清在线| 国产精品欧美日韩久久| 亚洲 日韩 国产第一| 午夜精品福利视频| 久久影院资源站| 欧美一级片在线播放| 色综合天天狠天天透天天伊人| 亚洲激情免费观看| 国产69久久精品成人| 亚洲美女久久久| 自拍偷拍亚洲精品| 992tv成人免费影院| 国内精品一区二区三区| 国产精品男人爽免费视频1| 中文字幕日韩欧美精品在线观看| 久久91亚洲精品中文字幕| 日韩av男人的天堂| 97精品国产97久久久久久春色| 亚洲欧美国产一本综合首页| 国产香蕉97碰碰久久人人| 一区二区三区视频免费在线观看| 欲色天天网综合久久| 中文字幕av一区二区三区谷原希美| 狠狠躁夜夜躁人人爽超碰91| 日韩美女视频免费在线观看| 日韩电影免费观看在线观看| 性欧美办公室18xxxxhd| 国模极品一区二区三区| 欧美精品一本久久男人的天堂| 国产精品精品视频一区二区三区| 国产精品色悠悠| 欧美一级片免费在线| 亚洲三级免费看| 日韩成人在线电影网| 亚洲激情视频网站| 亚洲电影免费观看高清完整版在线| 欧美性色xo影院| 欧美成年人视频网站欧美| www.欧美免费| 庆余年2免费日韩剧观看大牛| 欧美影院在线播放| 国产精品99久久久久久白浆小说| 97视频免费看| 日韩在线观看免费全集电视剧网站| 亚洲网站视频福利| 亚洲一区亚洲二区亚洲三区| 欧美一级黄色网| 欧美洲成人男女午夜视频| 国产精品大片wwwwww| 精品无人区太爽高潮在线播放| 这里只有精品视频| 2019av中文字幕| 95av在线视频| 欧美一级片免费在线| 久久九九亚洲综合| 91成人精品网站| 欧美日韩亚洲视频一区| 91po在线观看91精品国产性色| 亚洲国产精久久久久久| 午夜精品久久久久久久99热浪潮| 综合136福利视频在线| 一区二区三区天堂av| 成人a在线观看| 国产一区二区三区欧美| 亚洲新声在线观看| 一本色道久久综合狠狠躁篇的优点| 成人国产在线激情| 欧美多人爱爱视频网站| 中文字幕9999| 奇米成人av国产一区二区三区| 欧美美女18p| 国内精品免费午夜毛片| 久久五月情影视| 一区二区三区四区视频| 欧美激情中文字幕乱码免费| 91综合免费在线| 亚洲一区二区免费在线| 国产精品成人品| 亚洲免费av片| 亚洲精品成人免费| 日韩在线播放一区| 大量国产精品视频| 国产精品久久97| 欧美一区二粉嫩精品国产一线天| 精品偷拍一区二区三区在线看| 国语自产精品视频在线看一大j8| 日韩美女在线观看| 日韩性xxxx爱| 亚洲一区久久久| 亚洲欧美精品suv| 日韩av在线网址| 久久精品99国产精品酒店日本| 亚洲在线免费视频| 国产激情999| 成人亚洲欧美一区二区三区| 久久69精品久久久久久久电影好| 国产精品成人aaaaa网站| 55夜色66夜色国产精品视频| 美日韩丰满少妇在线观看| 亚洲欧洲第一视频| 91久久综合亚洲鲁鲁五月天| 日韩在线国产精品| 国产精品网站入口|