简体   繁体   中英

How to create Segue which make view controller fullscreen in Xcode 11.1

When I try to create segue via storyboard it's only does open new view controller as pop out instead of fullscreen. I tried changing kind of segue from,,Show (eg Push)" to others but then I get "Thread 1: signal SIGABRT"

You need to select present modally for the segue type and then right below select the presentation style full screen :

Xcode 截图

What you need to do is set the destination view controller's modalPresentationStyle to fullscreen by way of prepareForSegue:sender: :

class FirstViewController: UIViewController {

    ...

    @IBAction func segueButtonPressed(_ sender: Any) {
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        super.prepare(for: segue, sender: sender)

        if let secondViewController = segue.destination as? SecondViewController {
            secondViewController.modalPresentationStyle = .fullScreen
        }
    }
}

prepareForSegue:sender: is called before a segue is performed from a UIViewController . The default modalPresentationStyle in iOS 13+ is .pageSheet , which is the presentation that doesn't cover the whole screen (though it allows for more natural navigation/dismissal via swiping the view controller down and off the screen). We need to change this modalPresentationStyle to .fullScreen before performing the segue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM