Stop UIViewController Animation on dismiss - ios

I have a UIViewController that I display full screen, then when the user touches a button I present another view controller like so:
[self.navigationController pushViewController:loadSaveViewController animated:YES];
I like the animation that happens when I transition TO the view controller i.e. the main view shifts down and slides off to the left and the new view controller is displayed with the nav bar at the top.
HOWEVER, when I go back using the button at the top of the nav bar the screen does the opposite. The main screen appears, but with a nav bar at the top for a short time then the main screen shifts up.
How do I stop the main screen from doing the animation? When the user returns to the main screen, I do not want them to see the nav bar and the shift up, I just want the main screen to appear, or slide in.
Thanks for the help.

In iOS 7, there are new classes that will allow you to control every aspect of animation. This website is very useful ios 7 transitioning

Related

Analog of setViewControllers:animated: in NavigatorIOS

I would like to pop a view from the navigation stack (login screen) and immediately push another view (home screen) with NavigatorIOS.
In iOS I would achieve this using UINavigationController setViewControllers:animated:.
I have tried navigator.replace, navigator.replaceAtIndex but that doesn't quite work - it does replace the view but he navigation bar is hidden on the pushed screen (my login screen has it hidden, which is defined in its route properties), and there is no transition animation.
Another option that I tried is using navigator.pop followed by navigator.push. It did result in an animated transition but the login screen was still on the navigation stack (it wasn't popped) and the back button was visible.
What is the proper way to do this with NavigatorIOS?

UINavigationBar cutting the height of status bar

In iOS8, I have a root view controller where I would show another navigation view controller as the root vc's subview when user clicks on one button. I pre-loaded the navigation view controller in viewDidAppear to ensure responsiveness when user clicks on the button, since instantiating and adding subview would cause some latency.
However, if I put the setupNavigationVC() inside viewDidAppear(), my navigation bar would look like this when expanded to full screen.
if I let my code execute setupNavigationVC() right after user clicks the button, the navigation bar would look normal.
Also, I noticed that if I pause the app and then go back in. The navigation bar would return to normal. I suppose the OS must have reloaded every view when an app is resumed.
Thanks in advance!

Strange UINavigationItem behavior after using custom navigation transitioning animations

I am doing a custom UINavigationController pop transition animation.
But having a strange bug, I've made a sample project to demonstrate the issue (Taken from https://github.com/objcio/issue5-view-controller-transitions)
An navigation-based app, 2 view controllers.
The first viewController has 2 bar button items on the navigationBar, a button in the middle of view to push to second viewController.
The second viewController has a left bar button item to pop to the first viewController.
If the second view controller has been dragged less than 50%, my custom animation will cancel the transition, and if it's over 50%, it'll finish the transition, pop the viewController. (Just like the system default)
However, if the transition was cancelled, the navigation item's on the first view controller will be over-ridded.
The "back" item will appear on first view controller, and the right bar button item will disappear.
This is the video to demonstrate: https://youtu.be/qg2lUKsNtzk
And the source code is on github: https://github.com/JohnnyTseng/issue5-view-controller-transitions
Could somebody point out where the problem is? I've been debugging this issue for whole day. Thanks!
In iOS 7 Apple add new default navigation behavior. You can swipe from left border of the screen to go back on navigation stack.
you can stop this by putting this code in application delegate.
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
you can read more over here interactive pop gesture of navigation view controller

Transitioning between transparent navigation bar to translucent

In Apple's recently released Remote app I noticed the way in which the navigation bar behaves is unique and I haven't been able reproduce it. When popping the Now Playing view controller the navigation bar remains transparent for the Now Playing view controller and the navigation bar for the library view controller also stays translucent (Screenshot 1). I'm trying to figure out if they are using two navigation controllers or only one. Personally I feel they're using just one for two reasons (1) the interactive pop gesture is enabled; (2) when you press the 'Now Playing' button in the library view controller, just before the now playing screen has finished 'push view controller' animation the navigation bar becomes transparent (Screenshot 2). This is the behaviour I experience when pushing my view controller (which sets the navigation bar to transparent). So my question is: How does Apple present both navigation bars of the two view controllers as if they were individual (as with Screenshot 1), even the bar buttons, navigation title etc... are 100% in opacity when switching (usually when pushing/popping the buttons and titles of the previous view controller fade as the new controller is being pushed). I've tried playing around with the bar tint colour in viewDidAppear and viewWillAppear in both view controllers but cannot reproduce the same behaviour, and cannot prevent the bar buttons from fading.
Gosh I hope I've explained this well, I get confused just thinking about it!
Screenshot 1 (Popping):
Screenshot 2 (Pushing):
I just downloaded the application to make sure. Two different navigation bars are used. You can see this by using the interactive pop gesture. Notice how the navigation bar on the bottom view controller slides in and out. During normal push and pop transitions, the navigation items just fade in and out on the existing bar, while the bar is stationary. This is what happens up until the point where the now playing view controller is pushed.
If you look quickly, during the now playing view controller animation, you can see the bottom navigation bar disappear.
From my experience with UIKit behavior and what I see in the app, here is what I think happens:
album_vc = the bottom, list view controller
nowplaying_vc = the top view controller
On nowplaying_vc's viewWillAppear:
Set the navigation bar to hidden using [self.navigationController setNavigationBarHidden:YES animated:YES];. Since this is in animation block, this will make the navigation bar slide out during the push animation.
Set [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; Pretty sure about this, because notice there is no animation in the transition of the status bar styles. It just becomes white.
On nowplaying_vc's viewWillDisappear:
Set the navigation bar to shown using [self.navigationController setNavigationBarHidden:NO animated:YES];. Since this is in animation block, this will make the navigation bar slide in during the pop animation.
Set [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; Again, notice how during interactive pop gesture, the status bar just changes with no animation.
To achieve the transparent look of the navigation bar of nowplaying_vc, you can use an empty image ([UIImage alloc]) with setBackgroundImage:forBarPosition:barMetrics:.
Since the application does not rotate, we can't be sure if the navigation bar on nowplaying_vc is part of another navigation controller or just a navigation bar on the top with a position of UIBarPositionTopAttached. For all we know, there isn't even a navigation bar there but just a back chevron image view (back bar button is comprised of an image view and a button).
I think the status bar style is changed in viewWillAppear: and viewWillDisappear: due to the unnatural feel there is during interactive pop gesture. I would recommend using an animated transition, or even better, use the new view controller-based status bar style, which the system animates transitions by itself.
Update for modern API:
You should use the animateAlongsideTransition:completion: or animateAlongsideTransitionInView:animation:completion: API, rather than relying on the implicit animations of viewWillAppear: and viewWillDisappear:.
Instead of hiding and showing the navigation bar, you can update the alpha for the navigation bar. It will animate smoothly during the transition. For the view controller with transparent nav bar, instead of modifying the nav bar, create a navbar (or just the back button and title etc.) manually in the second controller's view. We will then hide the navbar when transitioning from first view controller to the second one.
On your first controller's viewWillDisappear and on your second view controller's viewWillAppear:, set the navigation bar alpha to zero using self.navigationController.navigationBar.alpha = 0;. Since this is in animation block, this will make the navigation bar disappear during the push animation.
Set the alpha back to one in first controller's viewWillAppear and second controller viewWillDisappear.

UINavigationController containment, iOS7 and Status Bar. Bug?

I'm updating my custom "iAD Banner Controller" to support iOS 7.
It's basically an UIViewController container composed of 3 views:
the main view (the view of the contained controller)
the banner view
a status bar background view
When the AD is available, there is an animated transition that makes the banner view and the status bar background view appear sliding from the top.
This is all managed using autolayout, and should appear like this (the status bar background is the green one, and in this case it contains an UINavigationController):
The problem is this: Using UINavigationController as the contained controller, when the banner is not visible, the nav controller extends 20px under the status bar. This is ok and expected.
But, when I move it's superview (the container) down to let the iAD banner appear, the 20px extension remains there, with this result:
However, if I do something like rotating the interface, the nav controller detects that the status bar is "far", and then adjusts itself.
I tried to call setNeedsStatusBarAppearanceUpdate and layoutIfNeeded respectively on the controller and it's view, without results.
I attach the whole project if you want to have a look: Link to the project
By now I solved using a workaround: when the AD appear / disappear I call
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
using this workaround, I force UINavigationController to detect again that the status bar is "far" and It has to recalculate the offset.
Since my view hierarchy is not so simple, and I want to re-use my AD Controller in other projects, I used a Notification to alert that the AD was appearing/disappearing.
I'll wait for other better answer a few day before marking this as correct.
Thanks

Resources