0
我們試圖沿着z訪問切換2個imageview視圖的位置切換。 2 imageViews是在屏幕上的2 到目前爲止,我已經嘗試使用CAAnimationGroup進行位置和旋轉,但它只顯示其中一個圖像,並且它看起來位置和旋轉關閉。這是代碼的樣子:爲2個圖像視圖的位置切換設置動畫
@IBOutlet weak var meMatchImageView: UIImageView!
@IBOutlet weak var theyMatchImageView: UIImageView!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
let groupAnimation = CAAnimationGroup()
groupAnimation.beginTime = 0.0
groupAnimation.duration = 1.5
groupAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut
)
groupAnimation.delegate = self
let rotationAnimation = CAKeyframeAnimation(keyPath: "transform.rotation")
rotationAnimation.values = [0, 0.14, 0]
rotationAnimation.keyTimes = [0, 0.5, 0]
let positionZAnimation = CABasicAnimation(keyPath: "position.z")
positionZAnimation.fromValue = -1
positionZAnimation.toValue = 1
let point0 = NSValue(cgPoint: CGPoint(x: 0, y: 0))
let point1 = NSValue(cgPoint: CGPoint(x: 110, y: -20))
let positionAnimation = CAKeyframeAnimation(keyPath: "position")
positionAnimation.values = [point0, point1, point0]
positionAnimation.keyTimes = [0, 0.5, 0]
groupAnimation.animations = [rotationAnimation, positionAnimation, positionZAnimation]
meMatchImageView.layer.add(groupAnimation, forKey: "switch")
theyMatchImageView.layer.add(groupAnimation, forKey: "switch")
}
任何幫助將不勝感激!