Home>

When transitioning to a different Storyboard with the following code, is it possible to make the transition source screen grayed out and transparently displayed like the attached image?
At present, I want to make the transparent display in grayout black out, and I think that it is impossible to do it from the transition method.
Please let me know if there is a way.

// Transition from MainViewController in MainStoryboard to AnotherViewController in AnotherStoryboard.
// MainViewController.swift
let storyboard: UIStoryboard = UIStoryboard (name: "AnotherStoryboard", bundle: nil)
let next: UIViewController = storyboard.instantiateInitialViewController () as! UIViewController
presentViewController (next, animated: true, completion: nil)


  • Answer # 1

    I write two ways.

    In both cases, the destination view controller should have a background color that is grayed out. The background color is black and the opacity is 15%, but you can. The keyword isoverCurrentContext.

    @ IBAction func tap (_ sender: UIButton) {
            let storyboard = UIStoryboard (name: "SecondViewController", bundle: nil)
            let next = storyboard.instantiateViewController (withIdentifier: "SecondViewController")
            next.modalPresentationStyle = .overCurrentContext
            present (next, animated: true, completion: nil)
    }

    Another

    Can the size of UIViewController itself be changed?

    I answered in

    , but this is how to set segue on Storyboard.

    Please choose one you like.