Bad animation when dismissing modal UIImagePickerController - iphone

I have a UIViewController (A) that modally presents a second view controller (B). Then, that second view controller modally presents a UIImagePickerController (IP). Basically, I have a stack of 2 modal view controllers.
(A) --modally presents--> (B) --modally presents--> (IP)
View controller (A) is the delegate of the image picker, and it dismisses the entire modal stack using:
[self dismissModalViewControllerAnimated:YES];
The problem is with the animation. When dismissing a modal stack like this, the currently visible view should slide off the bottom of the screen, revealing the newly visible view. So in this case, I expect (IP) to slide off the bottom of the screen, revealing the view for (A).
However, what actually happens is this: The image picker view simply disappears, immediately revealing the view for (A), and only the navigation bar animates off the bottom of the screen. The status bar is also left as black translucent instead of transitioning back to a standard gray; this seems to indicate that the image picker normally does some kind of "cleaning up" that isn't being performed when it's dismissed as part of a modal stack.
If I replace the image picker with another generic view controller, the animation works fine. If (IP) is dismissed by (B), the animation also works fine. The problem seems to occur only when dismissing multiple modal view controllers containing UIImagePickerController.
Has anyone seen this before? Any ideas what I might be doing wrong or how to work around this?

Unfortunately, the method dismissModalViewControllerAnimated does not work exactly as you would expect (at least not visually). To achieve what you want, you need to dismiss both modal viewcontrollers in a row, the first non-animated and the second one animated, as described e.g. here.

Related

View is blank after modalViewController is dismissed

I am using PPRevealSideViewController and I am showing a ViewController modally after user taps a cell in a side view. When I dismiss a modal view controller, the view, where user tapped, is shown blank. Only after I move a little bit side view, it is shown again (refreshed). What might be the problem?
This was a side effect of your preload call on viewWillAppear or DidAppear in fact. The view should not be preloaded if shown. I added this behavior as default into the controller.
But the idea behind was to test if [self.revealSideController sideDirectionOpened] != PPRevealSideDirection from the side you are trying to preload.
Fixed right here https://github.com/ipup/PPRevealSideViewController/commit/a1ca242422f0a8b4666df5987ca4a020f869bb99

View sizing with setting navigationbar to hidden with push/pop

So before I push a new viewController onto the stack in a certain view, I set the navigationBar to hidden I notice that it disappears before the next screen gets pushed and the slide animation happens (because I need a UIToolbar at the top).
So question #1: is there a way to push a new view controller and setting the navigationbar to hidden, and not getting the hide animation until after the new view controller is on screen. it looks funny that the navigation bar hides then pushes the new view controller.
Once the new view controller is present, when I pop it off, I set the navigation bar back
[self.navigationController.navigationBar setHidden:NO];
But when it is popped, the navigationbar is not back any more. Is it because this navigationBar is for the current navigationController and not the new one that is being presented after the pop? (question #2)
Question 3: Realizing it isn't showing my navigationBar, in the viewController that gets presented after the pop, in its viewDidAppear, I added
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController.navigationBar setHidden:NO];
}
which shows the navigationBar, but the view size is incorrect since it seems like once the navigation bar was hidden, the rest of the view took up the empty space, and then the navigationBar is on top of the content. Is there anything I can do about this? Or am I approaching it incorrectly with push and pop?(question #3).
Thanks!
I was running into the very same problem (only in reverse: I was starting from a NavigationBar being hidden and pushing a view where I wanted the NavigationBar visible), and there's actually an extremely easy fix.
Simply replace your calls:
[self.navigationController.navigationBar setHidden:NO];
with
[[self navigationController] setNavigationBarHidden:NO animated:YES];
In my code, I call these statements in the - (void)viewWillAppear:(BOOL)animated methods of each respective View Controller.
I just tried this solution in the order you are using (visible, then hidden), and it seems to work just as well.
Interesting issue. You could try changing the hidden property in viewWillAppear and viewWillDisappear, but it seems like that might not give the desired results either.
Can you present the view controller modally instead of making the navigation bar disappear? If it's the last view controller on the stack, that would be possible. It might also make more sense to the user to see a view controller presented differently. This might indicate to the user that navigating away from this view controller is no longer done with the Back Button. It could be more reasonable than having the navigation bar just disappear.
If you still wanted the view controller to slide in from the right, I don't think it can be done with a modal view controller. But, you could do that by animating a view that fills the screen. (You just add the view with a frame that has origin.x equal to the width of the screen. Then, in the animation, you change origin.x to 0.0. Let me know if you need more detail on this.)
However, I would recommend presenting the view controller in a different manner from the way a view is generally presented by a navigation controller. Because, essentially, you are no longer letting the user navigate away from this view as he/she generally would from within a navigation controller. (So, my response to question #3 would be 'yes'.)

How to get the animation right: inputView from a UINavigationController's nav bar?

I have a custom UIControl subclass with a UIPickerView as inputView. When the control is tapped, it calls becomeFirstResponder and the picker view automatically slides up from the bottom of the screen, like the system keyboard. This is working great!
The problem is that I am using the custom control as the titleView of a UINavigationItem. It functions properly, but if the view controller is popped off the navigation controller stack while the picker view is visible, the animation is wonky.
What I want to happen:
everything is pushed off screen to the right at the same time
What actually happens:
first, the background view and navigation bar slide off screen, the picker remains in place
then, after they are gone, the picker slides off to the right also
When I use the custom control inside the view controller's main view, it animates away just like the standard keyboard. So it seems as though this is a function of "coming from" the navigation bar, which is animated separately from the views inside.
How can I fix this, so that the inputView slides out with the rest of the content?
Turns out this can be fixed by calling endEditing: on the UINavigationController's view. In other words, within a view controller:
[self.navigationController.view endEditing:YES];
This causes the input view to slide down while the rest of the view slides off to the right. Not exactly the same as the system keyboard, but not obviously weird.

Dismissing multiple modal views

My application presents a modal view (A) from the main view that lets the user make a selection. When they make that selection it opens a second modal view (B) on top of the first one (A).
When I'm done with the second modal view (B), and want to dismiss it, I would like to dismiss the first one (A) and the second one (B) at the same time as I no longer need the user to return to that one (A) either.
The only thing I came up with is:
[self.parentViewController.parentViewController.parentViewController. dismissModalViewControllerAnimated:YES];
It works, but it just doesn't look correct. Is this OK to do or is there a more accepted way to do this?
I don't think that your way is wrong. It is what Apple documentation recommends:
If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
(UIApplication.sharedApplication().delegate! as! AppDelegate).navigationController?.viewControllers.first?.dismissViewControllerAnimated(true, completion: nil)

Contents of UIScrollView shifted after dismissing ModalViewController

I have a paged scrollview. Each page has a viewcontroller (buttonViewController) that manages a grid of buttons. If you press one of the buttons, the buttonViewController pops up another viewcontroller (detailViewController) modally.
The problem is, when I dismiss the modal view controller, the visible buttonViewController is shifted down by what looks like about 20 pixels. The weird thing is that only the visible page is shifted. If I scroll over to another page that is already loaded, it is still in the correct position.
My question is basically the same as dismissing modalViewController moves main view buttons around iphone
However, the accepted answer to that question assumed that the status bar is hidden. I am not hiding the status bar in my application.
Any other ideas?
One more note: The shift only happens the first time I launch a modal view controller. If I keep opening and closing the modal view controller, everything stays the same.
One further note: if I add the following code:
CGRect frame = self.view.frame;
frame.origin.y=0;
self.view.frame = frame;
after I dismiss the modal view controller, then I can work around the problem. The frame seems to move by 20pixels in y. I still don't know what's causing the move though.
Well I had this problem and it was due to the way my first viewController was set up (on the UIWindow), it is very weird since this had never happened to me before, the behavior I was observing was that when you add a subview at point (0,0) it would overlap with the status bar, which is not usual, usually the views know about the status bar and they behave appropriately. As a side effect, when one pushes a modal view that takes off the status bar, after dismissing it I saw the same problem you are seeing. What I did to fix was to set the UIWindows view to my controllers view in the nib, this seemed to fix everything. Once again I don't know why simply adding to the window programmatically with CGRectMake(0,0,320,460) had this odd behavior, since I have been doing this for all my previous projects and saw the correct behavior. But when I set it up in the nib, it worked as expected. Maybe this is your problem as well.
Turns out this was related to:
ModalViewController doesn't display during animation when paged scrollView is scrolled
I had mismatched the heights of some of my viewcontrollers, and that was throwing everything off.
Some of the views had heights of 460pixels, some had 480pixels. For some reason, this made it shift by 20pixels evertime a modal view controller disappeared. Once I made everything 460pixels, everything worked great.