我有一个CAKeyframeAnimation,它在横向上看起来不错,但是当设备旋转时,与其余内容相比,当设备旋转时,动画当然是不合适的。有没有办法调整(缩放)正在进行的动画的路径?CoreAnimation和设备旋转
编辑:添加代码
let circle = CAShapeLayer()
circle.path = UIBezierPath(roundedRect: CGRect(x: -60.0, y: -60.0, width: 100.0, height: 100.0), cornerRadius: 50.0).cgPath
circle.fillColor = UIColor.clear.cgColor
circle.strokeColor = UIColor.blue.cgColor
let animation = CAKeyframeAnimation(keyPath: "position")
animation.duration = (path["endTime"] as! Double) - (path["startTime"] as! Double)
animation.repeatCount = 0
animation.path = (path as! UIBezierPath).cgPath
animation.calculationMode = kCAAnimationPaced
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
circle.add(animation, forKey: "position")
self.view.layer.insertSublayer(circle, at: 5)
的问题是,所述UIBezierPath在纵向或横向定义(该应用支持),以便播放在相同的取向,它创建是没有问题的,但如果旋转设备,则应更新由UIBezierPath定义的动画以适应新的方向。我只是在寻找一种在动画时更新CAKeyframeAnimation路径到新坐标系的方法。
你有任何代码可以告诉我们吗? – dfd
所以你说你想改变动画_当它在animating_的中间,因为用户旋转了设备? – matt
确切!因为坐标系改变路径需要更新。我只是不知道该怎么做。 – Chris