【发布时间】:2016-09-29 21:09:37
【问题描述】:
我正在尝试使用透明背景(另一个UIView)制作一个弹出窗口(@987654321@)。 “弹出窗口UIView”一切正常,但我不知道如何带来“透明背景UIView”(在NavigationBar 和TabBar 上方)。
首先我在 Storyboard 中创建了 UIView 并连接了插座:
popupView.center = CGPointMake(CGRectGetMidX(self.view.bounds), tableView.center.y);
self.view.addSubview(popupView)
popupView.clipsToBounds = true
popupView.alpha = 0
然后,在显示 popupView 的同时,我正在创建透明背景 UIView:
func clicked() {
self.popupView.alpha = 1
let screenSize: CGRect = UIScreen.mainScreen().bounds
let opaqueView = UIView()
opaqueView.frame.size = CGSize(width: screenSize.width, height: screenSize.height)
opaqueView.backgroundColor = UIColor.blackColor()
opaqueView.alpha = 0.5
self.view.addSubview(opaqueView)
}
但是,背景视图不会超过 NavigationBar 或 TabBar。我试过了,但没有任何改变:
myTabBar.view.bringSubviewToFront(opaqueView)
我想要实现的是,popup UIView 位于最前面,opaque UIView 位于包括 NavBar 和 TabBar 在内的所有内容之上,但位于 popup UIView 之后
更新:
关于@Alex 的回答,通过这个块,我实现了在 TabBar 和 NavBar 上显示 opaqueView;但现在它也在 popupView 上方。
func display() {
popupView.center = CGPointMake(CGRectGetMidX(self.view.bounds), tableView.center.y);
self.view.addSubview(popupView)
popupView.clipsToBounds = true
let opaqueView = UIView()
let screenSize: CGRect = UIScreen.mainScreen().bounds
opaqueView.frame.size = CGSize(width: screenSize.width, height: screenSize.height)
UIApplication.sharedApplication().keyWindow!.insertSubview(opaqueView, belowSubview: popupView)
}
如何将 opaqueView 置于 popupView 下方,而 opaqueView 高于其他一切?
【问题讨论】:
标签: ios swift uiview addsubview