【发布时间】:2020-09-08 06:06:53
【问题描述】:
我在这里,被听起来像是一个基本问题的困扰......
我制作了一个运行 CABasicAnimation 的简单应用程序:如果我关闭应用程序并重新打开,动画仍在继续(这是完美的),但是如果我在同一个应用程序中更改屏幕然后返回,动画有停止(这很糟糕)。
当用户在同一个应用程序的另一个屏幕上时,任何提示可以帮助我解决问题并保持动画运行?
override func viewDidLoad() {
super.viewDidLoad()
swipeVC()
myCircle()
}
// Animated circle
func myCircle() {
// Center the shape
let center = view.center
// Create back shape
let backlayer = CAShapeLayer()
let circulationPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
// Designing the animated circle
backlayer.path = circulationPath.cgPath
backlayer.fillColor = UIColor.clear.cgColor
backlayer.strokeColor = UIColor.red.cgColor
backlayer.lineWidth = 5
view.layer.addSublayer(backlayer)
// Designing the animated circle
shapeLayer.path = circulationPath.cgPath
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 10
shapeLayer.strokeEnd = 0
shapeLayer.lineCap = .round
// Add gesture recgnition to activate the circle animation
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap)))
// Adding the circle to the main view
view.layer.addSublayer(shapeLayer)
}
【问题讨论】:
标签: ios swift cabasicanimation