先来张图让小伙伴们看一眼, 是不是效果很不错.
![](https://i-blog.csdnimg.cn/blog_migrate/2ca761ac22501fea8e5c8a7f80eb413d.webp?x-image-process=image/format,png)
自制做效果图
主要有四个View
黑色 XtPopViewController的self.view的颜色
白色 主控制器self.view颜色
在白色View上方 有个透明度为0.5的view 进行遮挡. (maskView)
下方的灰色View (popView1)
不多说直接上代码
let screen_Width = UIScreen.mainScreen().bounds.size.width
let screen_Height = UIScreen.mainScreen().bounds.size.height
class XtPopViewController: UIViewController {
/// 在底部弹出的View
var popView = UIView()
/// rootView
var rootView = UIView()
/// 主VC
var mainVc: UIViewController?
/// maskView
var maskView = UIView()
外部传参接口
func createPopViewControllerWithMainViewController(root: UIViewController, popView: UIView) -> Void {
self.mainVc = root
self.popView = popView
self.createSubviews()
}
创建视图
func createSubviews() {
self.view.backgroundColor = UIColor.blackColor()
mainVc!.view.frame = self.view.bounds
mainVc!.view.backgroundColor = UIColor.grayColor()
rootView = mainVc!.view
self.addChildViewController(mainVc!)
self.view.addSubview(rootView)
}
关键的打开方法
func openAction(){
UIApplication.sharedApplication().windows[0</