代码:
override func viewDidLoad() {
super.viewDidLoad()
gLog.verbose("self.view.frame=\(self.view.frame)")
self.view.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, SwitchListHeight)
gLog.verbose("self.view.frame=\(self.view.frame)")
self.view.backgroundColor = UIColor.clearColor()
// self.view.backgroundColor = nil
gLog.verbose("self.view.backgroundColor=\(self.view.backgroundColor)")
//self.view.backgroundColor=Optional(UIDeviceWhiteColorSpace 0 0)
}
结果:
2016-05-27 15:56:12.078 [Verbose] [main] [SwitchListTableViewController.swift:53] viewDidLoad() > self.view.frame=(0.0, 0.0, 320.0, 568.0)
2016-05-27 15:56:12.079 [Verbose] [main] [SwitchListTableViewController.swift:55] viewDidLoad() > self.view.frame=(0.0, 0.0, 320.0, 88.0)
2016-05-27 15:56:12.081 [Verbose] [main] [SwitchListTableViewController.swift:60] viewDidLoad() > self.view.backgroundColor=Optional(UIDeviceWhiteColorSpace 0 0)
显示出黑色,而不是透明色:
swift uiviewcontroller background clear but show black
iphone – Display clearColor UIViewController over UIViewController – Stack Overflow
改为:
let switchCustomerTypeListVC = SwitchListTableViewController(titleList: ["我的客户", "已交车客户"])
switchCustomerTypeListVC.view.backgroundColor = UIColor.clearColor()
gLog.verbose("self.modalPresentationStyle=\(self.modalPresentationStyle)")
self.modalPresentationStyle = .CurrentContext
gLog.verbose("self.modalPresentationStyle=\(self.modalPresentationStyle)")
self.presentViewController(switchCustomerTypeListVC, animated: true, completion: nil)
问题依旧。
改为:
let switchCustomerTypeListVC = SwitchListTableViewController(titleList: ["我的客户", "已交车客户"])
switchCustomerTypeListVC.view.backgroundColor = UIColor.clearColor()
gLog.verbose("switchCustomerTypeListVC.modalPresentationStyle=\(switchCustomerTypeListVC.modalPresentationStyle)")
switchCustomerTypeListVC.modalPresentationStyle = .CurrentContext
gLog.verbose("switchCustomerTypeListVC.modalPresentationStyle=\(switchCustomerTypeListVC.modalPresentationStyle)")
self.presentViewController(switchCustomerTypeListVC, animated: true, completion: nil)
有点效果了:
至少是状态栏和导航栏是,clear显示出来的了
但是还是有问题
并且去点击的话,还是可以点击到的。。。
改为:
let switchCustomerTypeListVC = SwitchListTableViewController(titleList: ["我的客户", "已交车客户"])
switchCustomerTypeListVC.view.backgroundColor = UIColor.clearColor()
gLog.verbose("switchCustomerTypeListVC.modalPresentationStyle=\(switchCustomerTypeListVC.modalPresentationStyle)")
//switchCustomerTypeListVC.modalPresentationStyle = .CurrentContext
switchCustomerTypeListVC.modalPresentationStyle = .OverCurrentContext
gLog.verbose("switchCustomerTypeListVC.modalPresentationStyle=\(switchCustomerTypeListVC.modalPresentationStyle)")
self.presentViewController(switchCustomerTypeListVC, animated: true, completion: nil)
终于可以完整显示透明的了:
ios – Swift UIView background color opacity – Stack Overflow
http://stackoverflow.com/questions/27439220/swift-uiview-background-color-opacity
uiviewcontroller – ModalViewController transparent background iOS 8 – Stack Overflow
ios – Swift Modal View Controller with transparent background – Stack Overflow
objective c – iOS: Modal ViewController with transparent background – Stack Overflow
iphone – Display clear colored ViewController over another ViewController in iOS 7 – Stack Overflow
[总结]
好像主要就是:
将要显示出来的VC的modalPresentationStyle,设置为UIModalPresentationStyle.OverCurrentContext
就可以了。