2016-05-31 58 views
0

我試圖在彈出視圖的頂部放置一個UIView - popupView,彈出視圖的另一個UIView(opaqueView),但在其他任何地方。 PopUpView與Outlet連接。把子視圖放在一切之上,但在另一個UIView之下

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) 
} 

使用這種方法導致opaqueView被放置在包括popupView在內的所有東西上。相反,我希望有popupView上述opaqueView但保持opaqueView高於一切只(視圖,TabBar,所以的NavBar)

+0

爲什麼你將'popupView'添加到'self.view',而將'opaqueView'添加到'keyWindow'? – kennytm

+0

因爲,如果我不在'keyWindow'中添加'opaqueView','opaqueView'沒有得到TabBar和NavigationBar。 – senty

+1

爲什麼不將popupView添加到keyWindow呢? – kennytm

回答

1

parent.insertSubview(child, belowSubview: sibling)作品時siblingparent直接孩子,讓childsibling共享相同的父。目前的代碼不起作用,因爲opaqueView(孩子)和popupView(該sbiling)有不同的父母。

表示①popupView應該使用keyWindow作爲父母,或者②opaqueView應該使用self.view作爲父母。既然你想opaqueView高於一切,選項①是唯一的解決方案。

相關問題