2015-12-30 65 views
1

視圖原來這就是我想要做的事:是向上的動畫沒有填寫屏幕

這裏是初始畫面:

enter image description here

當點擊底部箭頭有從底部過渡較小視圖頂部是這樣的:

enter image description here

正如你可以看到後面的景色變暗了。當我點擊後視圖時,較小尺寸的視圖通過向下動畫消失。

有幾件事我嘗試了: 1.我試圖模仿,似乎動畫正確,即從底部到頂部,但它涵蓋了整個後視圖。 2.我試圖通過試圖複製這篇文章使模式視圖只有父母大小的一半:Present modal view controller in half size parent controller。但是,它沒有工作。 3.所以我決定把一個UIView在我的後視圖的頂部,像這樣:

enter image description here

我連接與@IBOutlet weak var messageView: UIView!的灰色視圖。我試着用這個代碼:UIView.transitionWithView(messageView, duration: 1.0, options: UIViewAnimationOptions.CurveEaseIn, animations: nil, completion: nil)。然而,似乎沒有任何事情發生。有關如何完成此任務的任何建議?

+0

爲什麼你的動畫在'transitionWithView'中是'nil'?你假設把你的動畫代碼放在那裏,比如改變你想要動畫的子視圖的偏移量,然後它會開始。如果你希望後屏幕變灰,並從下面按下小菜單,最簡單的方法是先創建它們,但隱藏在「動畫」塊中,然後取消隱藏它們並更改它們的偏移量 – Tj3n

回答

0

對於按鈕的動畫:

自動佈局約束添加到BottomLayout Guide.And創建一個IBOutlet作爲

@IBOutlet weak var bottomConstraint: NSLayoutConstraint! 
var shouldAnimateView:Bool = true 

在按鈕的操作,你需要動畫視圖使用約束

@IBAction func showOrHideViewBtn(sender: AnyObject) { 

    if shouldAnimateView { 
     self.bottomConstraint.constant = self.view.frame.size.height/2+5 
     UIView.animateWithDuration(Double(0.2), animations: { 
      self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height 
      self.view.layoutIfNeeded() 
     }) 


    }else{ 

     self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height 
     UIView.animateWithDuration(Double(0.2), animations: { 
      self.bottomConstraint.constant = self.view.frame.size.height/2+5 
      self.view.layoutIfNeeded() 
     }) 


    } 
    shouldAnimateView = !shouldAnimateView 

}