我有一個圓圈,我想讓它跳動。
func drawCircle(context: CGContext) {
let circle = CGRect(x: circleX, y: circleY, width: circleDiameter, height: circleDiameter)
context.setFillColor(UIColor.systemPink.cgColor)
context.addEllipse(in: circle)
}
但我只是不明白如何在 CGContext 中做到這一點
uj5u.com熱心網友回復:
這是使用 CoreAnimation 的一種方法:
func drawCircle(context: CGContext) {
context.setFillColor(UIColor.systemPink.cgColor)
context.addEllipse(in: CGRect(x: bounds.origin.x,
y: bounds.origin.y,
width: bounds.width,
height: bounds.height))
context.fillPath()
// Using CoreAnimation
let animation = CABasicAnimation(keyPath: "transform.scale")
animation.repeatCount = .infinity
animation.duration = 2
animation.toValue = 1.5
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
animation.autoreverses = true
layer.add(animation, forKey: nil)
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444107.html
