[英]Bring Subview Above Everything But Below Another UIView
I am trying to place a UIView
- popupView at the top, and another UIView
(opaqueView) below popupView but above anything else. 我试图将一个
UIView
-popupView放在顶部,并在popupView下方但在其他任何上方放置另一个UIView
(opaqueView)。 PopUpView is connected with an Outlet. 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)
opaqueView.alpha = 0.6
UIApplication.sharedApplication().keyWindow!.insertSubview(opaqueView, belowSubview: popupView)
}
Using this approach causes the opaqueView getting placed over everything including the popupView. 使用这种方法会使opaqueView放置在包括popupView在内的所有内容上。 Instead, I want to have popupView above opaqueView but keep opaqueView above everything else (view, TabBar, NavBar)
相反,我希望在opaqueView上方具有popupView,但在所有其他内容(视图,TabBar,NavBar)上方保持opaqueView
parent.insertSubview(child, belowSubview: sibling)
works only when the sibling
is a direct child of parent
, so that child
and sibling
share the same parent. parent.insertSubview(child, belowSubview: sibling)
仅在sibling
是parent
的直接子代时起作用,以便child
和sibling
共享同一父代。 The current code does not work because opaqueView
(the child) and popupView
(the sbiling) have different parents. 当前代码不起作用,因为
opaqueView
(子级)和popupView
(sbiling)具有不同的父级。
That means either ① popupView
should use the keyWindow
as the parent, or ② opaqueView
should use self.view
as parent. 这意味着要么①
popupView
应该使用keyWindow
作为母体,或② opaqueView
应该使用self.view
作为父节点。 Since you want opaqueView
be above of everything, option ① is the only solution. 由于您希望
opaqueView
在一切之上,因此选项①是唯一的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.