动画后同步模型层与演示?

时间:2015-01-09 17:14:04

标签: ios core-animation

我有一个gestureRecognizer,其平移连接到视图。平移移动视图然后当我释放手指时,我有一个动画将其移回到它开始的位置。这一切都有效。当我尝试在动画之后同步模型和表示层时会出现问题,因此它不会在动画之前返回到位置。当我添加这个新代码时,视图首先跳起来,然后动画,然后最后跳回来。我究竟做错了什么?

// Animation
var animation = CABasicAnimation()
animation.keyPath = "position.y"
animation.byValue = -panLength!
animation.duration = 1
self.view.layer.addAnimation(animation, forKey: "basic")    // Run animation

// Sync model to presentation layer so that view don't snap back to former position.
var currentPos = self.view.layer.position
currentPos.y -= panLength!
self.view.layer.position = currentPos // Sync model and pressentation layer.

Screenshot of simulator http://www.zamzar.com/download.php?uid=1bb237dc1b54a7d79c5f52c38715ea-ddbfdec855bd14d6&targetID=12Sr3NF0Ch8sOBNQrQinrOM_ZDHIILMpt&fileID=p19b7q9rca4is3b31a4m2qgaof4.gif

1 个答案:

答案 0 :(得分:0)

我找到的解决方案使用了另一种设置动画的方法:

            // Animation
            UIView.animateWithDuration(0.7, delay: 0.0, options: .CurveEaseOut, animations: {
                var frame = self.view.layer.frame
                frame.origin.y -= self.panLength!
                self.view.layer.frame = frame

                }, completion: { finished in
                    println("Animation done!")
            })0