我使用animateWithDuration:completion完成UIView的某些屬性的動畫處理。這些動畫完成後,我想從他的超級視圖中刪除此視圖。 問題是,如果我添加完成塊內removeFromSuperView我沒有得到動畫。我發現的解決方法是刪除dispatch_after中的視圖。爲什麼?移除animateWithDuration完成塊內的UIView:完成
var loadingView: Loading! //This is a UIView loaded from a Nib
let delaySecs: NSTimeInterval = 2
UIView.animateWithDuration(delaySecs, animations: {() -> Void in
self.loadingView.cherrysImageView.transform = CGAffineTransformMakeScale(2, 2)
self.loadingView.cherrysImageView.alpha = 0
}) { (succeed) -> Void in
//Can't remove the view here, otherwise i get NO animation
//self.loadingView.removeFromSuperview()
}
//And if i add this instead of removing the view in the completion block, it works as expected
let delay = delaySecs * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {() -> Void in
self.loadingView.removeFromSuperview()
}
我複製了你的代碼,並且它可以很好地移除完成塊中的超級視圖。 – rdelmar