Modal window in swift

1

I need to make a modal window in swift .

The code I have in the controller that launches the modal is this:

if segue.identifier == "modal" {
   let vc = segue.destination as! ModalViewController
   vc.modalPresentationStyle = .currentContext
}

But the whole screen takes care of me

I want something similar to this:

    
asked by 03.11.2016 в 10:25
source

1 answer

0

You could do something like this:

On your MainController.swift:

func showModal() {
    let modalViewController = ModalViewController()
    modalViewController.modalPresentationStyle = .OverCurrentContext
    presentViewController(modalViewController, animated: true, completion: nil)
}

On your ModalViewController.swift:

class ModalViewController: UIViewController {
    override func viewDidLoad() {
        view.backgroundColor = UIColor.clearColor()
        view.opaque = false
    }
}

If you're working with storyboard

Add the Storyboard Dry with the Present Modally option to your ModalViewController and add the following values:

Background = Clear Color
Drawing = Desactiva the Opaque checkbox
Presentation = Over Current Context

Make sure the segue only uses the DEFAULT value for the presentation and the transition. Using the current context for presentation causes the mode to turn black instead of remaining transparent.

    
answered by 03.11.2016 / 11:10
source