Ios 在动画完成后执行序列

Ios 在动画完成后执行序列,ios,swift,segue,uiviewanimation,Ios,Swift,Segue,Uiviewanimation,我正在尝试在动画完成后执行一段。以下是我在viewDidAppear中的代码: override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) imageViewAnimated.startAnimating() if label.center != CGPoint(x:50, y:10) { UIView.animateWithDuration(2.0

我正在尝试在动画完成后执行一段。以下是我在viewDidAppear中的代码:

    override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    imageViewAnimated.startAnimating()


    if label.center != CGPoint(x:50, y:10) {

        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            self.label.center = self.view.center

            }, completion: nil)

        UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            //                self.label.center = CGPoint(x: 50,y:300)
            self.label.alpha = 0.0

            }, completion: nil)
    }

    if label.alpha == 0.0 {
        UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in

            self.performSegueWithIdentifier("backSegue", sender: self)

            }, completion: nil)
    }
}

所以基本上我有一个向下移动并淡出的标签(第一个和第二个animateWithDuration),然后我希望在标签淡出和其他动画完成后出现这个序列。现在segue正在发生,但它会立即执行,并且不会等待,无论延迟增加多少。

完成后运行segue代码。您必须在“完成”块上对其进行编码。方法完成动画后将调用完成块

 UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in

               //if you perform segue here if will perform with animation

                }, completion: { finished in

      //if you perform segue it will perform after it finish animating.

     self.performSegueWithIdentifier("backSegue", sender: self)


    })

完成后运行序列代码。您必须在“完成”块上对其进行编码。方法完成动画后将调用完成块

 UIView.animateWithDuration(0.5, delay: 10.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in

               //if you perform segue here if will perform with animation

                }, completion: { finished in

      //if you perform segue it will perform after it finish animating.

     self.performSegueWithIdentifier("backSegue", sender: self)


    })

你打错电话了。你想要这样的东西:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    imageViewAnimated.startAnimating()

    if label.center != CGPoint(x:50, y:10) {
        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            self.label.center = self.view.center
        }, completion: nil)

        UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            //                self.label.center = CGPoint(x: 50,y:300)
            self.label.alpha = 0.0
        }, completion: { finished in
            self.performSegueWithIdentifier("backSegue", sender: self)
        })
    }
}

你打错电话了。你想要这样的东西:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    imageViewAnimated.startAnimating()

    if label.center != CGPoint(x:50, y:10) {
        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            self.label.center = self.view.center
        }, completion: nil)

        UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { () -> Void in
            //                self.label.center = CGPoint(x: 50,y:300)
            self.label.alpha = 0.0
        }, completion: { finished in
            self.performSegueWithIdentifier("backSegue", sender: self)
        })
    }
}

您可以在动画块的完成处理程序部分编写导航代码,因为该完成处理程序将在动画完成后启动

[UIView animateWithDuration:0.25 animations:^{
    //Animation changes
} completion:^(BOOL finished) {
    //Navigation
}];

您可以在动画块的完成处理程序部分编写导航代码,因为该完成处理程序将在动画完成后启动

[UIView animateWithDuration:0.25 animations:^{
    //Animation changes
} completion:^(BOOL finished) {
    //Navigation
}];

如果要在函数完成后执行任何操作,则必须在“完成”块上对其进行编码。完成块将在方法完成其工作后被调用。我已经更新了答案只是检查如果您想在函数完成后执行任何操作,那么您必须在“完成”块上对其进行编码。完成块将在方法完成其工作后被调用。我已经更新了答案,请检查谢谢它的工作!我不知道为什么,但这需要一段时间(大约15秒来完成这个过程)。可能是我的电脑太慢了。谢谢,它能用!我不知道为什么,但这需要一段时间(大约15秒来完成这个过程)。可能是我的电脑太慢了。请注意问题的标签是Swift,而不是Objective-C。请注意问题的标签是Swift,而不是Objective-C。