登录 立即注册
金钱:

仿UC浏览器图片加载进度条

来自: yinxing_cb 分类: iOS精品源码 上传时间: 2016-4-29 15:55:26
Tag:进度条 progress animation 动画 animation

项目介绍:

详细代码,请下载附件代码


主要代码:
[Objective-C] 查看源文件 复制代码
主要代码:
中间的做动画的View
- (void)drawRect:(CGRect)rect{
    CGFloat width = rect.size.width;
    CGFloat height = rect.size.height;
    CGContextRef context=UIGraphicsGetCurrentContext();
  
    //眼睛
    CGFloat eyeRadius = width * 0.1;
    CGFloat factor_eyeX = 0.3;
    CGFloat factor_eyeY = 0.2;
    CGPoint leftEyeCenter = CGPointMake(width * factor_eyeX, height * factor_eyeY);
    CGPoint RightEyeCenter = CGPointMake(width - width * factor_eyeX, height * factor_eyeY);
    CGContextAddArc(context, leftEyeCenter.x, leftEyeCenter.y, eyeRadius, 0, M_PI * 2, 0);
    CGContextAddArc(context, RightEyeCenter.x, RightEyeCenter.y, eyeRadius, 0, M_PI * 2, 0);
    
    if (_faceColor) {
        [_faceColor set];
    }
    
    CGContextDrawPath(context, kCGPathFill);
    //嘴
    CGFloat factor_pX = 0.15;
    CGFloat factor_pY = 0.6;
    
    CGFloat factor_cX = 0.5;
    CGFloat factor_cY = 0.8;
    
    CGPoint startPoint = CGPointMake(width * factor_pX, height * factor_pY);
    CGPoint endPoint = CGPointMake(width - width * factor_pX, height * factor_pY);
    CGPoint controlPoint = CGPointMake(width * factor_cX, height * factor_cY);
    //贝塞尔曲线
    CGContextMoveToPoint(context, startPoint.x, startPoint.y);
    CGContextAddQuadCurveToPoint(context, controlPoint.x, controlPoint.y, endPoint.x, endPoint.y);
    CGContextSetLineWidth(context, 2.0);
    CGContextDrawPath(context, kCGPathStroke);

}

进度条:
self.outLayer             = [CAShapeLayer layer];
        UIBezierPath *path        = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.rectRadius];
        self.outLayer.strokeColor = self.fixedLineColor.CGColor;
        self.outLayer.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];

相关源码推荐:

我来说两句
*滑动验证:
所有评论(2)
yinxing_cb 2016-4-29 15:59:58
主要代码:
中间的做动画的View
- (void)drawRectCGRect)rect{
    CGFloat width = rect.size.width;
    CGFloat height = rect.size.height;
    CGContextRef context=UIGraphicsGetCurrentContext();
  
    //眼睛
    CGFloat eyeRadius = width * 0.1;
    CGFloat factor_eyeX = 0.3;
    CGFloat factor_eyeY = 0.2;
    CGPoint leftEyeCenter = CGPointMake(width * factor_eyeX, height * factor_eyeY);
    CGPoint RightEyeCenter = CGPointMake(width - width * factor_eyeX, height * factor_eyeY);
    CGContextAddArc(context, leftEyeCenter.x, leftEyeCenter.y, eyeRadius, 0, M_PI * 2, 0);
    CGContextAddArc(context, RightEyeCenter.x, RightEyeCenter.y, eyeRadius, 0, M_PI * 2, 0);
   
    if (_faceColor) {
        [_faceColor set];
    }
   
    CGContextDrawPath(context, kCGPathFill);
    //嘴
    CGFloat factor_pX = 0.15;
    CGFloat factor_pY = 0.6;
   
    CGFloat factor_cX = 0.5;
    CGFloat factor_cY = 0.8;
   
    CGPoint startPoint = CGPointMake(width * factor_pX, height * factor_pY);
    CGPoint endPoint = CGPointMake(width - width * factor_pX, height * factor_pY);
    CGPoint controlPoint = CGPointMake(width * factor_cX, height * factor_cY);
    //贝塞尔曲线
    CGContextMoveToPoint(context, startPoint.x, startPoint.y);
    CGContextAddQuadCurveToPoint(context, controlPoint.x, controlPoint.y, endPoint.x, endPoint.y);
    CGContextSetLineWidth(context, 2.0);
    CGContextDrawPath(context, kCGPathStroke);

}

进度条:
self.outLayer             = [CAShapeLayer layer];
        UIBezierPath *path        = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.rectRadius];
        self.outLayer.strokeColor = self.fixedLineColor.CGColor;
        self.outLayer.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];


回复
yangdj2000 2016-5-31 16:18:12
很不错的 啊  很给力
回复
938 0 0
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表