2016-09-25 45 views
8

如何在Swift 3中做一個簡單的完成塊?UIView.animate - Swift 3 - 完成

我想設置self.isOpen = true在完成的動畫:

  UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: { 
       self.isOpen = true 
       self.drawerView?.frame = CGRect(x: 0, y: 0, width: (self.drawerView?.frame.size.width)!, height: (self.drawerView?.frame.size.height)!) 
       self.contentView?.frame = CGRect(x: 200, y: 0, width: (self.contentView?.frame.size.width)!, height: (self.contentView?.frame.size.height)!) 
      }, completion: nil) 

在傳:

這是非常不可能的學習斯威夫特3個大氣壓,由於互聯網上的工作NOTHING :(


我也搜遍了整個文件,甚至提到單詞 「動畫」,但沒有找到任何東西:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/index.html#//apple_ref/doc/uid/TP40014097-CH3-ID0

+1

對於未來:後自動生成.animate(...)函數,雙擊藍色突出顯示的((Bool) - > Void)?編輯器佔位符和匿名塊的結構將準備:) – Muli

回答

49

你加入這樣的:

UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: { 
    self.drawerView?.frame = CGRect(x: 0, y: 0, width: (self.drawerView?.frame.size.width)!, height: (self.drawerView?.frame.size.height)!) 
    self.contentView?.frame = CGRect(x: 200, y: 0, width: (self.contentView?.frame.size.width)!, height: (self.contentView?.frame.size.height)!) 
}, completion: { (finished: Bool) in 
    self.isOpen = true 
}) 
+0

感謝一堆!他們的「建議」太神祕了,無法理解實際上寫什麼...以及缺少文檔,以及壓倒性數量的非工作swift2.2-代碼是相當令人沮喪的:( –

+0

動畫是偉大的,但我怎麼能相同按鈕單擊時按下佈局? – pmb

-2

寫類似下面的代碼:

UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: { 

// code 

}) 
+0

此答案不包含完成塊,這是問題的要求。 – frakman1