执行自定义segue后,UITabBar消失

时间:2016-09-08 10:36:29

标签: ios swift segue uitabbar uistoryboardsegue

执行自定义segue后, UITabBar 消失。 UITabBar控制器中嵌入了两个视图

Segue之前的第一个观点: First View Before Segue

Segue之后的第二种观点: Second View After Segue

Segue之后的第一个观点: First View After Segue

主要故事板: Main Storyboard

自定义搜索代码:

import UIKit

class CustomPushSegue: UIStoryboardSegue {

override func perform(){

    // Assign the source and destination views to local variables.
    let firstVCView = self.sourceViewController.view as UIView!
    let 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(screenWidth, 0.0, screenWidth, screenHeight)

    //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.35, 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)
    }
}

}

Custom Unwind Segue:

import UIKit

class CustomPushUnwindSegue: UIStoryboardSegue {


override func perform() {

    // Assign the source and destination views to local variables.
    let secondVCView = self.sourceViewController.view as UIView!
    let firstVCView = 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, 0.0, screenWidth, screenHeight)

    //Insert the destination view above the current (source) one.
    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(firstVCView, aboveSubview: secondVCView)


    // Animate the transition.
    UIView.animateWithDuration(0.35, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
        secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)

    }) { (Finished) -> Void in

        self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
    }
}

}

0 个答案:

没有答案