簡體   English   中英

UIStoryboardSegue:動畫過程中不顯示視圖

[英]UIStoryboardSegue: view is not displayed during animation

當執行自定義segue的動畫時,目標視圖顯示為黑色。 動畫結束后,視圖將出現並且看起來不錯。

這是屏幕截圖:

動畫場景:

動畫/動畫完成后的視圖:

這是自定義segue類:

class SegueToPreview: UIStoryboardSegue {

override func perform() {
    // Assign the source and destination views to local variables.
    var firstVCView = self.sourceViewController.view as UIView!
    var secondVCView = self.destinationViewController.view as UIView!

    // Get the screen width and height.
    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height

    // Specify the initial position of the destination view.
    secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

    // Access the app's key window and insert the destination view above the current (source) one.
    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    // Animate the transition.
    UIView.animateWithDuration(0.2, animations: { () -> Void in

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

        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                animated: false,
                completion: nil)
    }

}

盡管放松的搜索效果很好,但同時顯示了兩種視圖。

我想在執行動畫時不會加載視圖,但是不知道如何解決該問題。

目標vc視圖的初始位置設置不正確(假設您希望視圖從右側移入); 您將其放置在屏幕下方,而不是屏幕右側,

secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

應該是

secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)

暫無
暫無

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

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