Creating a modal view with a transparent Swift background

I have what I would consider a fairly easy task. Basically I have one view controller with some data, let it view controller A. When you click the button, I want the second view controller (B) to display the overlay of the first. However, I do not want B to completely cover A. I want B to be smaller and basically create a dark transparent background through which you can still see A.

I tried this through the storyboard, where I create a modal shogi and then play with the presentation options (form, sheet, etc.), but basically it always happens that the view controller B just flows up and covers all the letters A.

There are several tutorials in iOS 7 and Objective-C, but I have not yet been able to translate them into Swift / ios 8 (this is also for the iPhone).

I'm not sure if anyone else tried this in ios 8, but if someone can give me some tips on how to do this, that would be awesome.

Thank!

+4
source share
1 answer

Try the following in prepareForSegue -

    toBePresentedVC.view.backgroundColor = UIColor.clearColor()
    presentingViewController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext      
    presentingViewController.presentViewController(self, animated: true completion: nil)

You can try several alpha options with a background color to get a transparent effect with some color.

+8
source

All Articles