gpt4 book ai didi

swift - 防止关键帧动画完成后 View 弹回

转载 作者:行者123 更新时间:2023-11-30 13:33:03 26 4
gpt4 key购买 nike

我有一个 View ,我正在以这样的方式对其进行动画处理,使其扩展并移动到 View Controller 中的一组新坐标。我正在使用关键帧执行此操作:

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)

问题在于,一旦动画完成, View 就会返回到其原始位置和大小。

有没有办法防止这种情况在 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)
})

关于swift - 防止关键帧动画完成后 View 弹回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36370674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com