swift之弹出一个背景半透明的UIViewController

坑爹的背景半透明,按网上给出oc的方法,动画结束之后,半透明效果消失。通过各种折腾,各种试验,终于搞定了。

let viewController=storyboard.instantiateViewControllerWithIdentifier("对应要启动的ViewController名字") as 对应要启动的ViewController名字
viewController.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5) 
self.presentViewController(vPersonalizedSettingsViewController, animated: 动不动画随便你, completion: nil)

  

这里要注意的是,要启动的viewController必须要在这里设置半透明,如果在对应的UIViewController viewDidLoad里面设置是没有半透明的!

然后要启动的UIViewController viewDidLoad的时候设置

self.modalPresentationStyle = .Custom

这样成功半透明。  

原文地址:https://www.cnblogs.com/helloandroid/p/4286677.html