我有这个UIGestureRecognizer,它在其函数中嵌套了一个动画,并且在该函数的结尾,我想实例化一个viewController。实现此目的的正确方法是什么?这是我的代码:

func longPress(gesture:UILongPressGestureRecognizer)
    {
        if gesture.state == UIGestureRecognizerState.Began
        {
            oldbounds = self.imageView.bounds

            let bounds = self.imageView.bounds
            UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.4, initialSpringVelocity: 10, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                self.imageView.bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width + 40, height: bounds.size.height + 40)
            }, completion: nil)

            println("user pressed on image")
        }
        else if gesture.state == UIGestureRecognizerState.Changed
        {
            gesture.state == UIGestureRecognizerState.Began
        }
        else
        {
            let bounds = self.imageView.bounds
            UIView.animateWithDuration(0.2, animations: {
                self.imageView.bounds = self.oldbounds
            })

            println("user release on image")
        }
    }

我想代码应该在第一个gesture.state条件下位于动画的完成部分,但是我不知道这样做的正确代码实现。

最佳答案

UIView.animateWithDuration具有一个completion block。在动画制作完成后,您可以在此处运行代码。例如,您要启动viewController的代码会去那里。

示例

    UIView.animateWithDuration(0.3, animations: {
    //Do animation stuff here
}, completion: { (complete: Bool) in
   //Create your view controller here and show on screen
})

关于ios - 如何在动画结束时实例化viewController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32515474/

10-15 19:09
查看更多