亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

IOS中的循環進度條

IOS中的循環進度條

智慧大石 2019-12-12 13:04:30
我想創建一個圓形的進度條,如下所示:如何使用Objective-C和Cocoa做到這一點?我開始做的是創建UIView和編輯drawRect,但是我有點迷茫。任何幫助將不勝感激。謝謝!
查看完整描述

3 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

我的魔術數字示例(以便更好地理解):


  CAShapeLayer *circle = [CAShapeLayer layer];

  circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(29, 29) radius:27 startAngle:-M_PI_2 endAngle:2 * M_PI - M_PI_2 clockwise:YES].CGPath;

  circle.fillColor = [UIColor clearColor].CGColor;

  circle.strokeColor = [UIColor greenColor].CGColor;

  circle.lineWidth = 4;


  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

  animation.duration = 10;

  animation.removedOnCompletion = NO;

  animation.fromValue = @(0);

  animation.toValue = @(1);

  animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

  [circle addAnimation:animation forKey:@"drawCircleAnimation"];


  [imageCircle.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];

  [imageCircle.layer addSublayer:circle];


查看完整回答
反對 回復 2019-12-12
?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

對于Swift來說,


let circle = UIView(frame: CGRectMake(0,0, 100, 100))


circle.layoutIfNeeded()


let centerPoint = CGPoint (x: circle.bounds.width / 2, y: circle.bounds.width / 2)

let circleRadius : CGFloat = circle.bounds.width / 2 * 0.83


var circlePath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: CGFloat(-0.5 * M_PI), endAngle: CGFloat(1.5 * M_PI), clockwise: true    )


let progressCircle = CAShapeLayer()

progressCircle.path = circlePath.CGPath

progressCircle.strokeColor = UIColor.greenColor().CGColor

progressCircle.fillColor = UIColor.clearColor().CGColor

progressCircle.lineWidth = 1.5

progressCircle.strokeStart = 0

progressCircle.strokeEnd = 0.22


circle.layer.addSublayer(progressCircle)


self.view.addSubview(circle)


查看完整回答
反對 回復 2019-12-12
  • 3 回答
  • 0 關注
  • 775 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號