设为首页 加入收藏

TOP

仿UC浏览器图片加载进度条(二)
2017-10-13 10:33:44 】 浏览:3353
Tags:浏览器 图片 加载 进度
utLayer.lineWidth
= _lineWidth; self.outLayer.fillColor = [UIColor clearColor].CGColor; self.outLayer.lineCap = kCALineCapRound; self.outLayer.path = path.CGPath; [self.layer addSublayer:self.outLayer]; self.progressLayer = [CAShapeLayer layer]; self.progressLayer.frame = self.bounds; self.progressLayer.fillColor = [UIColor clearColor].CGColor; self.progressLayer.strokeColor = self.actionLineColor.CGColor; self.progressLayer.lineWidth = _lineWidth; self.progressLayer.lineCap = kCALineCapRound; self.progressLayer.path = path.CGPath; [self.layer addSublayer:_progressLayer]; self.progress = 0; } return self; } - (void)willMoveToSuperview:(UIView *)newSuperview{ if (self.isAnimated) { _animatedTimer = [NSTimer scheduledTimerWithTimeInterval:_timeInterval target:self selector:@selector(animation) userInfo:nil repeats:YES]; [_animatedTimer fire]; [[NSRunLoop mainRunLoop] addTimer:_animatedTimer forMode:NSRunLoopCommonModes]; } } - (void)removeFromSuperview{ [super removeFromSuperview]; [_animatedTimer invalidate]; _animatedTimer = nil; LogFunc; } - (void)dealloc{ LogFunc; } - (void)animation{ __weak typeof(self) weakSelf = self; CGRect tempF = weakSelf.myFaceView.frame; tempF.origin.y = 2 * _myFaceViewInset - _myFaceViewInset * 0.5; [UIView animateWithDuration:weakSelf.timeInterval * 0.5 animations:^{ weakSelf.myFaceView.frame = tempF; } completion:^(BOOL finished) { CGRect tempF_= weakSelf.myFaceView.frame; tempF_.origin.y = weakSelf.myFaceViewInset * 0.5; [UIView animateWithDuration:weakSelf.timeInterval * 0.5 animations:^{ weakSelf.myFaceView.frame = tempF_; }]; }]; } - (void)setActionLineColor:(UIColor *)actionLineColor{ _actionLineColor = actionLineColor; self.progressLayer.strokeColor = self.actionLineColor.CGColor; } - (void)setFixedLineColor:(UIColor *)fixedLineColor{ _fixedLineColor = fixedLineColor; self.outLayer.strokeColor = self.fixedLineColor.CGColor; } - (void)setProgress:(CGFloat)progress{ if (progress<0) { progress = 0; } if (progress>1) { progress = 1; } _progress = progress; self.progressLayer.strokeEnd = progress; } - (void)layoutSubviews{ [super layoutSubviews]; _myFaceView.frame = CGRectInset(self.bounds, _myFaceViewInset, _myFaceViewInset); }

我把源码上传到了GitHub,大家下载之后可以直接使用,非常方便。地址在这 https://github.com/CoderPaulYin/YXProgressView.git

基本的使用举例:

 _myProgressView = [[YXProgressView alloc] initWithFrame:CGRectMake(0, 100, 80, 80)];
    _myProgressView.centerX = self.view.centerX;
    _myProgressView.actionLineColor = [UIColor greenColor];//设置进度条的填充颜色,也可以设置其他颜色
    [self.view addSubview:_myProgressView];

然后在其他需要更新进度的地方:

- (void)sliderValueChanged:(UISlider *)sender{
    NSLog(@"%f",sender.value);
    _myProgressView.progress = sender.value;
}

我的QQ:82154139  GitHub:  https://github.com/CoderPaulYin   

 欢迎加我好友交流,互相学习。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C 数组 下一篇内外分离接口依赖及UIScrollView..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目