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,332
  • 6
  • 37
  • 69
senty
  • 12,385
  • 28
  • 130
  • 260

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,815
  • 1
  • 29
  • 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