Swift 防止关键帧动画完成后视图捕捉回来

Swift 防止关键帧动画完成后视图捕捉回来,swift,core-animation,Swift,Core Animation,我有一个视图,我正在以这样的方式设置动画,它将展开并移动到视图控制器中的一组新坐标。我使用关键帧执行此操作: UIView.animateKeyframesWithDuration(0.5, delay: 0, options: .CalculationModeCubic, animations: { UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.5) { //Moving main V

我有一个视图,我正在以这样的方式设置动画,它将展开并移动到视图控制器中的一组新坐标。我使用关键帧执行此操作:

UIView.animateKeyframesWithDuration(0.5, delay: 0, options: .CalculationModeCubic, animations: {
    UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.5) {

        //Moving main View
        tappedView.frame = CGRectMake((self.screenSize.width/2)-250, (self.screenSize.height/2)-250, 500, 500)

    }
}, completion: nil)
问题在于,一旦动画完成,视图将返回到其原始位置和大小


有没有办法防止Swift中出现这种情况?

如果使用自动布局,这是一个问题。在这种情况下,必须将最终坐标放入完成处理程序中,以使其工作

Swift 2

UIView.animateKeyframesWithDuration(0.5, delay: 0, options: .CalculationModeCubic, animations: {
    UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.5) {
        // Moving main View
        tappedView.frame = CGRectMake((self.screenSize.width/2)-250, (self.screenSize.height/2)-250, 500, 500)
    }
}, completion: {(finished: Bool) -> Void in
    tappedView.frame = CGRectMake((self.screenSize.width/2)-250, (self.screenSize.height/2)-250, 500, 500)
})
Swift 3、4、5

UIView.animateKeyframes(withDuration: 0.5, delay: 0, options: .calculationModeCubic, animations: {
    UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5) {
        // Moving main View
        tappedView.frame = CGRect(x: (self.screenSize.width/2)-250, y: (self.screenSize.height/2)-250, width: 500, height: 500)
    }
}, completion: {(finished: Bool) -> Void in
    tappedView.frame = CGRect(x: (self.screenSize.width/2)-250, y: (self.screenSize.height/2)-250, width: 500, height: 500)
})