【发布时间】:2019-05-19 18:40:53
【问题描述】:
我正在努力解决一个奇怪的问题,例如当我向任何图层添加比例变换时,它不会从中心进行动画处理。它是从原点开始的。
func addSquareBorderLayer() {
borderLayer = CAShapeLayer()
let rect = CGRect(x: spotlight!.frame.origin.x, y: spotlight!.frame.origin.y, width: spotlight!.frame.width, height: spotlight!.frame.height)
borderLayer?.path = UIBezierPath(roundedRect: rect, cornerRadius: spotlight!.cornerRadius).cgPath
borderLayer?.strokeColor = UIColor(red: 91/255, green: 186/255, blue: 162/255, alpha: 1).cgColor //ColorRGB(91, 186, 162)
borderLayer?.lineWidth = spotlight!.cornerRadius
borderLayer?.fillColor = UIColor.clear.cgColor
layer.addSublayer(borderLayer!)
animatePulsatingLayer(pulsatingLayer: layer)
}
private func animatePulsatingLayer(pulsatingLayer : CALayer) {
let animation = CABasicAnimation(keyPath: "transform.scale")
animation.duration = 0.5
animation.repeatCount = .greatestFiniteMagnitude
animation.autoreverses = true
animation.fromValue = 1
animation.toValue = 1.05
pulsatingLayer.add(animation, forKey: "pulsing")
}
有人可以帮忙吗?
参考正在发生的事情:https://www.dropbox.com/s/0hqdrrv310du7vz/mo.mov?dl=0
【问题讨论】:
-
CALayer - CABasicAnimation not scaling around center/anchorPoint 的可能重复项。将 CAShapeLayer 的
bounds设置为非零值,例如原点为零且大小为spotlight.frame.size的矩形。 -
@KurtRevis 我已经尝试了所有可能的解决方案。谢谢
标签: ios animation core-animation calayer