我有一個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