2017-07-14 72 views
0

我試圖掩蓋的ViewController當我this screenshot.呈現視圖像我提出我的看法的方式由固定在屏幕這樣的外:如何通過它呈現視圖時掩蓋的ViewController

addContactTopAnchor = addContact.bottomAnchor.constraint(equalTo: 
view.topAnchor) 
addContactTopAnchor.isActive = true 
addContact.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true 
addContact.heightAnchor.constraint(equalToConstant: 182).isActive = true 

,當我按下一個按鈕,我將其移動到顯示器上是這樣的:

func addTapped(){ 
     self.addContactTopAnchor.isActive = false 
     self.addContactTopAnchor = addContact.bottomAnchor.constraint(equalTo: view.topAnchor, constant: 182) 
     self.addContactTopAnchor.isActive = true 
     UIView.animate(withDuration: 0.3, animations: {() -> Void in 
      self.view.layoutIfNeeded() 
     }) 
    } 

我想掩蓋一切,除了視圖就像它在我的截圖顯示。

+1

在您的動畫塊中放置一個透明的黑色UIView並將其設置爲alpha?完成後不要忘記刪除視圖。 – Desdenova

+0

我試過這個,但面具也覆蓋了我正在動畫的視圖,有沒有一種方法可以讓我把這個視圖放在我用作面具的頂部? – RickS

+1

其實我只是想通了,謝謝,我能夠把它帶到前臺self.view.bringSubview(toFront:self.addContact) – RickS

回答

1

我創建的視圖

let mask: UIView = { 
    let view = UIView() 
    view.backgroundColor = .black 
    view.alpha = 0 
    return view 
}() 

在我的按鈕按壓,我設置的α和把我的視圖到前

func addTapped() { 
    self.addContactTopAnchor.isActive = false 
    self.addContactTopAnchor = addContact.topAnchor.constraint(equalTo: view.bottomAnchor, constant: -182) 
    self.addContactTopAnchor.isActive = true 
    UIView.animate(withDuration: 0.3, animations: {() -> Void in 
     self.view.layoutIfNeeded() 
     self.mask.alpha = 0.5 
     self.navigationController?.navigationBar.alpha = 0.5 
     self.navigationController?.navigationBar.shadowImage = UIImage() 
     self.view.bringSubview(toFront: self.addContact) 
    }) 
} 

編輯:此外,我已將此添加掩蔽導航欄:

 self.navigationController?.navigationBar.alpha = 0.5 
     self.navigationController?.navigationBar.shadowImage = UIImage() 

感謝@desdenova的幫助

相關問題