4

I need to manage the transition between two ViewControllers embedded in a NavigationController that uses the standard, light, blurred layer. All of the ViewControllers in this part of the app looks really good with this blurred layer except for one whereas I want it to fade over to become a completely transparent bar and go back to normal when I pop this ViewController.

Desired behaviour:

enter image description here

I've looked into this a long time but I can't figure out how to accomplish it. Can anyone help me with it? I've looked into this question but I don't quite understand how to implement it.

Thank you!

Community
  • 1
  • 1
Erik
  • 2,500
  • 6
  • 28
  • 49

1 Answers1

7

Have you looked into UIViewControllerTransitionCoordinator?

Each UIViewController has a transitionCoordinator property you can access to perform tasks that are related to a transition.

From the viewWillAppear/viewWillDisappear methods of the UIViewController doing the transition call the animateAlongsideTransition method of the transitionCoordinator:

id <UIViewControllerTransitionCoordinator> coordinator = [self transitionCoordinator];

[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
    // animate the changes in the navigation bar here
} completion:nil];
pNre
  • 5,376
  • 2
  • 22
  • 27
  • I see, so what I would do would be to put this code in the "opaque" VC and the transparent VC? What method would be the most appropriate? – Erik Feb 05 '15 at 13:19
  • That really depends on the transition effect you want to achieve and on the views you are animating. If you want to fade the transparent VC background, then add the code in the transparent VC. – pNre Feb 05 '15 at 13:37
  • My intent is to make the UINavigationBar (or UINavigationItem) fade out, so that on VC1, it'll be completely normal and light, blurred, then - upon segue, fade it out to become completely transparent. The VC itself stays the same – Erik Feb 05 '15 at 13:38
  • I'd put the code in the `UIViewController` that requires the `UINavigationBar` to change, the pushed one. – pNre Feb 05 '15 at 13:40
  • So only that ViewController, so it should handle both the push segue and the pop segue back to it? But in what method? Like viewWillAppear, etc – Erik Feb 05 '15 at 13:45
  • In `viewWillAppear` and `viewWillDisappear` to cover both cases. – pNre Feb 05 '15 at 13:49
  • Will that animation block make it animate hand in hand with the segue? So that the animation animates together with the segue, so that if the user took the far left screen and swiped it over, it would gradually animate the same way? – Erik Feb 05 '15 at 13:51
  • The animations are added to the same group, give a look at the documentation link in my answer. – pNre Feb 05 '15 at 13:52
  • Great. But how can I fade out the navigationBar, normally I would use the alpha property, but it isn't available – Erik Feb 05 '15 at 13:54
  • I'm sure that this has already been discussed, try searching SO. – pNre Feb 05 '15 at 14:03
  • I see I couldn't do navigationBar.alpha = CGFloat; but I could do [navigationBar setAlpha:CGFloat]; – Erik Feb 05 '15 at 14:07
  • I made it work now, but the other UITableViewController (VC1, the one that starts push) resizes the tableView, so upon pop, the top row can't be tapped – Erik Feb 05 '15 at 14:10
  • I'm not sure about what your are saying but don't set the alpha level to 0, use a slightly greater value. – pNre Feb 05 '15 at 14:11
  • Something like 0.00001? Also, I need a back button on the viewcontroller that is pushed to, would it be a good idea to just create a UIButton at the right spot and make it look like a "normal" back button? – Erik Feb 05 '15 at 14:14
  • In that case you would also have to make touches pass through the `UINavigationBar`. However I feel we are getting out of topic here, now you know how to make a smooth transition, if you need help on the `UINavigationBar` itself maybe it's better to post another question. – pNre Feb 05 '15 at 14:22
  • 1
    Yeah, agree - I'll post a new question if I can't figure it out. Thanks a lot for the help! – Erik Feb 05 '15 at 14:29