Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

swift - Transparent background for modally presented viewcontroller

I am using Parse & ParseUI. I want my PFLoginViewController subclass to have a transparent background. In the future, I want to lay a blurred view over the background.

But.... Once the animate-in of the PFLoginViewController is done, the background turns black... Whilst 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 logincontroller's used subclass:

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?

P.s. Applying the clearColor to the backgroundColor in the subclass makes no difference

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Fixed it.

The problem was that presentViewController does not keep the view that I was covering.

viewController.modalPresentationStyle = .overCurrentContext

did the trick.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...