I'm animating some properties of a UIView with animateWithDuration:completion. After those animations are complete i want to remove this view from his superview. The problem is that if i add inside the completion block removeFromSuperView i dont get animations at all. The workaround i found is to remove the view inside dispatch_after. Why?
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()
}