簡體   English   中英

Swift中沒有動畫的自定義segue

[英]Custom segue without animation in Swift

我正在嘗試在沒有任何動畫的情況下在兩個視圖控制器之間進行自定義選擇。 一切正常,正如我期望的那樣,只有控制台會給我以下消息:

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)
}

不用動畫就可以做到:

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

展示新的UIViewController和parentViewController:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM