tomvanzummeren / TZStackView

UIStackView replica for iOS 7.x and iOS 8.x
MIT License
1.16k stars 129 forks source link

Completion closure never called when animating showing/hiding #70

Open nico75005 opened 8 years ago

nico75005 commented 8 years ago

UIView.animateWithDuration(0.5, animations: { subview.hidden = false }, completion: { finished in // never called when changing hidden property of a subview of TZStackView })

nico75005 commented 8 years ago

A workaround is to use a CATransaction:

CATransaction.begin()

CATransaction.setCompletionBlock( {
    // code to call once the animation is over
} )

subview.hidden = false

CATransaction.commit()
EliaCereda commented 8 years ago

I’ve encountered this problem too, nice workaround! Is the completion block never called in your experience? In my case it works the first time, but not on subsequent calls.

I suspect the cause is this line in the code of TZStackView.observeValueForKeyPath(…):

UIView.setAnimationDelegate(self)

It’s just a guess, but I think UIView implements the completion callback by setting some internal object as the delegate of the animation. Which then brings the question, does calling UIView.setAnimationDelegate inside a CATransaction result in the correct behavior? Could you do a quick test and see if TZStackView.hiddenAnimationStopped is called in your code?

EDIT: it seems issue #50 is referring to the same problem, this definitely needs to be looked into. Unfortunately it’s going to be a while before I’m able to do it myself, but I will if it hasn’t been fixed yet.

CosynPa commented 8 years ago

Fixed in #72