【发布时间】:2017-01-22 19:00:32
【问题描述】:
我有一个 CAKeyframeAnimation,它在横向上看起来很棒,但是当设备旋转时,与其他内容相比,动画当然是不合适的。有没有办法调整(缩放)正在进行的动画的路径?
编辑:添加代码
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 路径更新到新坐标系的方法。
【问题讨论】:
-
你有什么代码可以给我们看吗?
-
所以你是说你想在动画制作过程中改变动画,因为用户旋转了设备?
-
没错!因为坐标系改变了路径需要更新。我只是不知道该怎么做。
标签: swift core-animation screen-rotation