目前正在開發一些swift程序,並且我有一個行動號召,我從超級視圖中移除blurview,同時我爲兩個按鈕設置動畫。Swift:removefromSuperview刪除約束
一切正常,但有一個小問題。當我從超級視圖中移除模糊視圖時,我的2個按鈕上的約束在底部設置爲0,並從該位置開始動畫。
我不希望他們轉移到0.如果我不刪除blurview我的動畫是完美的工作。我檢查了我的按鈕約束是否與blurview相關,但事實並非如此。因爲我認爲它只能在我們的限制與blurview相關時重置。
我的故事板看起來如下:
view
|-> camera_view
|-> blur_view
|-> record_label
|-> record_button
我正在執行是下面的代碼:
@IBAction func recordButton(sender: AnyObject) {
self.blurView?.removeFromSuperview()
UIButton.animateWithDuration(0.3, delay: 0.2, options: .CurveEaseOut, animations: {
var recordButtonFrame = self.recordButton.frame
var recordLabelFrame = self.recordLabel.frame
recordButtonFrame.origin.y -= recordButtonFrame.size.height
recordLabelFrame.origin.y -= recordLabelFrame.size.height
self.recordButton.frame = recordButtonFrame
self.recordLabel.frame = recordLabelFrame
}, completion: { finished in
print("Button moved")
})
}
我在做什麼錯?
親切的問候,
沃特
self.blurView?.hidden = true –
謝謝你解決我的問題。忘了那個。它仍然留在記憶中這種方式是正確的?如果我再次需要blurview的實例,這種方法會更快,但如果我不需要它,速度會更慢? – Wouter125
是的,如果你只是隱藏它將保留在內存中。也許你可以先隱藏它,然後在動畫結束後將其刪除。 –