【问题标题】:Custom segue without animation in SwiftSwift中没有动画的自定义segue
【发布时间】:2015-06-16 14:16:56
【问题描述】:

我正在尝试在没有任何动画的两个视图控制器之间进行自定义 segue。一切都按我的预期工作,只是控制台给我以下消息:

2015-06-16 12:19:01.537 prototyp_2[42453:9048104] 不平衡调用 的开始/结束外观过渡。

这是我的代码:

class Segue_forward: UIStoryboardSegue {

    override func perform() {

        // zdroj a destinace do lokálních proměnných
        var firstVCView = self.sourceViewController.view as UIView!
        var secondVCView = self.destinationViewController.view as UIView!

        // rozměry displeje
        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height

        // initial position of destination view
        secondVCView.frame = CGRect(x: 0.0, y: 0.0, width: screenWidth, height: screenHeight)

        // protože destination VC není subview okna aplikace tak to musime napravit
        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVCView, aboveSubview: firstVCView)

        // animace
        UIView.animateWithDuration(0.0, animations: { () -> Void in

            firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, 0.0)
            secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, 0.0)

        }) { (Finished) -> Void in

            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)

        }


    }

}

这是我的行动:

@IBAction func nextQuestion(sender: AnyObject) {
   self.performSegueWithIdentifier("id_forwardSegue", sender: self)
}

【问题讨论】:

    标签: ios swift uiviewcontroller segue


    【解决方案1】:

    不用动画就可以了:

    override func perform() {
        self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)
    }
    

    【讨论】:

    • 非常感谢!我不知道如何实现无动画。
    【解决方案2】:

    用 parentViewController 呈现新的 UIViewController:

    self.sourceViewController.parentViewController?.presentViewController(YOUR_VIEW_CONTROLLER, animated: false, completion: nil)
    

    【讨论】:

      猜你喜欢
      • 2015-01-08
      • 2012-06-02
      • 1970-01-01
      • 2013-10-15
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多