【问题标题】:Performing segue after animation takes long动画后执行 segue 需要很长时间
【发布时间】:2016-09-08 14:28:54
【问题描述】:

我正在尝试在 Swift 中的动画完成块中执行转场。但是,segue 需要很长时间(大约 10 秒)才能完成,我不知道为什么。代码如下:

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.alpha = 0.0

                }, completion: { finished in

                    self.poof.alpha = 1.0
                    self.performSegueWithIdentifier("backSegue", sender: nil)
            })
        }
    }

【问题讨论】:

  • 新视图是否加载了大量数据?
  • 新视图只是一个文本框和按钮,但旧视图中加载了很多大图像。
  • 为什么viewController一出现就转换离开?
  • 它应该在视图控制器出现几秒钟后转换,一旦动画完成。
  • 动画是否立即生效?还是要花很长时间才能看到动画?

标签: ios xcode swift swift2 xcode6


【解决方案1】:
 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.alpha = 0.0

                    }, completion: { finished in

                        self.poof.alpha = 1.0
                        dispatch_async(dispatch_get_main_queue(),{
                            self.performSegueWithIdentifier("backSegue", sender: nil)
                        })
                })
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 2011-03-14
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多