Ios 使用animatewithduration移动图像视图
我尝试多次移动图像。这就是我尝试实现它的方式Ios 使用animatewithduration移动图像视图,ios,xcode,swift,uiimageview,animatewithduration,Ios,Xcode,Swift,Uiimageview,Animatewithduration,我尝试多次移动图像。这就是我尝试实现它的方式 override func viewDidAppear(animated: Bool) { UIView.animateWithDuration(1, animations: { () -> Void in self.sattelite.center.x = 50 self.sattelite.center.y = 100 self.sattelite
override func viewDidAppear(animated: Bool) {
UIView.animateWithDuration(1, animations: { () -> Void in
self.sattelite.center.x = 50
self.sattelite.center.y = 100
self.sattelite.center.x = 50
self.sattelite.center.y = 50
self.sattelite.center.x = 50
self.sattelite.center.y = 300
})
}
然而,animatewithduration方法只执行一个动作。是否有任何方法可以为图像视图的所有三个运动设置动画?谢谢。您需要将动画链接到完成或使用关键帧动画您需要将动画链接到完成或使用关键帧动画您可以轻松链接动画;完成后再开始一次:
- 这里有一个例子:
//1st animation UIView.animateWithDuration(1.0, delay: 0.0, options: .CurveEaseInOut | .AllowUserInteraction, animations: { //some code ex : view.layer.alpha = 0.0 }, completion: { finished in //second animation at completion UIView.animateWithDuration(1.0 , delay: 0.0, , options: .CurveEaseInOut | .AllowUserInteraction, , animations: { () -> Void in //some code ex : view.layer.alpha = 1.0 } , completion: { finished in //third animation at completion UIView.animateWithDuration(1.0, delay: 0.0, options: .CurveEaseInOut | .AllowUserInteraction, animations: { //some code ex : view.layer.alpha = 0.0 }, completion: { finished in //FINISH : 3 animations!!! }) }) })
- 这里有一个例子:
//1st animation UIView.animateWithDuration(1.0, delay: 0.0, options: .CurveEaseInOut | .AllowUserInteraction, animations: { //some code ex : view.layer.alpha = 0.0 }, completion: { finished in //second animation at completion UIView.animateWithDuration(1.0 , delay: 0.0, , options: .CurveEaseInOut | .AllowUserInteraction, , animations: { () -> Void in //some code ex : view.layer.alpha = 1.0 } , completion: { finished in //third animation at completion UIView.animateWithDuration(1.0, delay: 0.0, options: .CurveEaseInOut | .AllowUserInteraction, animations: { //some code ex : view.layer.alpha = 0.0 }, completion: { finished in //FINISH : 3 animations!!! }) }) })
class func animateWithDuration(_ duration: NSTimeInterval,
animations animations: () -> Void,
completion completion: ((Bool) -> Void)?)
仅在动画
上执行第一个动画,并在完成
中启动第二个动画。第三步是完成第二步
因此,基本上是一系列动画,其中每一个动画在前一个动画完成时开始。使用具有完成的动画版本:
class func animateWithDuration(_ duration: NSTimeInterval,
animations animations: () -> Void,
completion completion: ((Bool) -> Void)?)
仅在动画
上执行第一个动画,并在完成
中启动第二个动画。第三步是完成第二步
所以基本上是一系列动画,每一个都是在前一个动画结束时开始的。它执行哪一个动作?它执行哪一个动作?