Transparent background for modally represented viewcontroller

I am using Parse and ParseUI. I want my subclass of PFLoginViewController to have a transparent background. In the future, I want to blur the look on the background.

But ... As soon as the PFLoginViewController animation is complete, the background turns black ... So far, during the animation, the background was transparent.

func presentLogin() { var loginViewController = LoginViewController() var signupViewController = SignUpViewController() loginViewController.fields = .UsernameAndPassword | .LogInButton | .PasswordForgotten | .SignUpButton | PFLogInFields.DismissButton signupViewController.fields = .UsernameAndPassword | .Email | .DismissButton | .SignUpButton loginViewController.delegate = self loginViewController.logInView.backgroundColor = UIColor.clearColor() loginViewController.logInView.opaque = false signupViewController.delegate = self loginViewController.signUpController = signupViewController self.presentViewController(loginViewController, animated: true) { () -> Void in // } } 

My subtitle used to log in:

 class LoginViewController: PFLogInViewController { @IBOutlet weak var _nmcLogoLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let userName = SettingsManager.userName let password = SettingsManager.password self.logInView.usernameField.text = userName self.logInView.passwordField.text = password NSBundle.mainBundle().loadNibNamed("LoginViewBranding", owner: self, options: nil)[0] as? UIView self.logInView.logo = _nmcLogoLabel } } 

How can I make it transparent?

Ps Applying clearColor to backgroundColor in a subclass doesn't matter

+44
swift parse-platform
Dec 27 '14 at 17:30
source share
4 answers

I fixed it.

The problem was that presentViewController did not save the view that I was covering.

 viewController.modalPresentationStyle = .overCurrentContext 

did his job.

+116
Dec 27 '14 at 18:07
source share

Part of the solution is hidden in the question. You need three lines to make the background transparent, namely. isOpaque = false backgroundColor =.clear and set modalPresentationStyle

Here is the complete solution. In the calling View Controller, call this function:

 func presentModal() { let modalController = ModalViewController() modalViewController.modalPresentationStyle = .overCurrentContext present(modalViewController, animated: true, completion: nil) } 

And in ModalViewController viewDidLoad() :

 override func viewDidLoad() { super.viewDidLoad() view.isOpaque = false view.backgroundColor = .clear // try other colors, say: .white or black with Alpha etc. } 
+32
Jun 01 '17 at 11:14
source share

similar to the selected answer, but visually through IB:

enter image description here

+22
Dec 04 '16 at 3:03
source share

In case someone is still struggling with a transparent background, I found this solution some time ago - I can’t remember where, but it still works fine with the latest Xcode & Swift.

 ContactListViewController2: UIViewController, UITableViewDelegate, UITableViewDataSource,UIViewControllerTransitioningDelegate { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.modalPresentationStyle = .custom self.transitioningDelegate = self } 
0
Jul 11 '19 at 12:59 on
source share



All Articles