func makeACircle(circle: UIView, stokeStart: Double, duration: Double){
var progressCircle = CAShapeLayer();
let centerPoint = CGPoint (x: circle.bounds.width/2, y: circle.bounds.width/2);
let circleRadius : CGFloat = circle.bounds.width/2
var circlePath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: CGFloat(-0.5 * M_PI), endAngle: CGFloat(1.5 * M_PI), clockwise: true );
progressCircle = CAShapeLayer();
progressCircle.path = circlePath.cgPath;
progressCircle.strokeColor = UIColor.white.cgColor;
progressCircle.fillColor = UIColor.clear.cgColor;
progressCircle.lineWidth = 10;
progressCircle.strokeStart = 0;
progressCircle.strokeEnd = 1;
progressCircle.borderWidth = 1
progressCircle.borderColor = UIColor.black.cgColor
circle.layer.addSublayer(progressCircle);
// progressCircle.clipsToBounds = false
self.view.addSubview(circle)
let animation = CABasicAnimation(keyPath: "strokeEnd")
// Set the animation duration appropriately
animation.duration = duration
// Animate from 0 (no circle) to 1 (full circle)
animation.fromValue = stokeStart
animation.toValue = 1
// Do a linear animation (i.e. the speed of the animation stays the same)
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
// Set the circleLayer's strokeEnd property to 1.0 now so that it's the
// right value when the animation ends.
progressCircle.strokeEnd = 1.0
// Do the actual animation
progressCircle.add(animation, forKey: "animateCircle")
}
Я рисую круги с указанным выше кодом. Он рисует круг вокруг кнопок на экране, которые представляют время, прошедшее с момента создания кнопки. Этот код работает, но когда я иду на рабочий стол и возвращаюсь, все круги на экране полностью заполняются независимо от того, сколько осталось времени. Если в приложении я перейду на другую страницу, а затем вернусь, он ее исправит.Возобновление рисования CAShapeLayer при просмотре реенёров переднего плана?
Я звоню makeACircle внутри этого firebase запроса
currentUserRef?.child("invitedToPosts").queryOrdered(byChild: "timestamp").queryStarting(atValue: cutoff).observe(.childAdded) { (snapshot: FIRDataSnapshot) in
После того, как у меня достаточно информации о кнопке, чтобы быть сделано, я сделать кнопку, а затем вызвать makeACircle.
Любые идеи о том, как предотвратить круги, не появляясь, как если бы они достигли strokeEnd, когда я загружаюсь с главной страницы?