2

Is there a way to give an animation completion closure for a UINavigationController animation?

I have a line such as,

navigationController?.setNavigationBarHidden(navigationController?.navigationBarHidden == false, animated: true) 

and I want to detect when it's completed.

Is there any way to achieve that?

Jeff Wolski
  • 6,302
  • 6
  • 36
  • 69
senty
  • 11,415
  • 25
  • 114
  • 244

1 Answers1

8
CATransaction.begin()
CATransaction.setCompletionBlock { print("Finished") }
navigationController?.setNavigationBarHidden(!navigationController!.navigationBarHidden, animated: true)
CATransaction.commit()

You can wrap it around with CATransaction.

Eendje
  • 8,585
  • 1
  • 28
  • 31
  • Thanks a lot. By the way, I think navigationBarHidden booleans are not behaving as expected. What is the trick behind it? What should I observe. It feels like it's behaving on its own even when I use true or false – senty Apr 09 '16 at 03:32