My application has a paged scrollview. Each page of the scrollview has an instance of a view controller (buttonViewController) that shows a grid of buttons. If the user clicks on one of the buttons, buttonViewController launches a detailViewController modally, with animation set to YES.
If I'm viewing the first page (furthest left) or the scroll view, everything work's correctly. However, if I am scrolled to any of the other pages, the modal view animation (sliding up from the bottom in this case) doesn't appear. Instead, the whole view goes black for the same length of time that the animation would run for, and then the modal view controller appears fully displayed. The same thing happens when dismissing the modal view controller.
The code is completely standard. In my buttonViewController I call:
[self presentModalViewController:detailController animated:YES];
The same code runs no matter which page I'm looking at (though on different instances of buttonViewController of course.)
How would I start debugging this?
This might have to do with the frame of the detailController...When you are in a UIScrollView, the first page is between 0 and 320, however when you scroll that offset increments, so (assuming you have full screen pages) the next view will be 320 and 640, the next one will be in 640 and (640+320), and so on and so forth. So when you are setting up your detailController with frame CGRectMake(0,0,320,460), when you are in the first page, the animation will look fine, but when you are in any other page the animation will take place at (0,0) and then im guessing the viewcontroller sees this is not the active screen a nd moves the modal view controller to where the active screen is. If you initialize your frame like this CGRectMake(320*pageNumber,0,320,460) I think youll have the d esired behavior you are looking for. Let me know if this works im curious myself.
You need to insert a UIView (or any kind of view e.g. UIScrollView) under the view you are trying to animate, you will get the animation work correctly. I guess this is because you are providing a view that the animation is based on.
Related
I am currently executing my own version of this opening animation
http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial
The animation runs perfectly however once the default.png disappears and my animation starts the UITabBar and the UIPicker I have loaded in the first view are sitting above my animation when it plays.. I am wondering how to make sure this animation plays above everything.
Before running the animation, call:
[self.view bringSubviewToFront:basketTop];
[self.view bringSubviewToFront:basketBottom];
[self.view bringSubviewToFront:napkinTop];
[self.view bringSubviewToFront:napkinBottom];
This basically pulls those 4 objects to the front of the view, so they are on top of everything else. You might need to play around with the order in which you bring the 4 to the front.
Except for the z-order you should check that the view you are trying to animate has the proper size, otherwise it can't possibly cover the whole screen. And of course check your view's superview - if the superview covers only the area between UITabBar and UIPicker it won't cover them, ever.
In your application:didFinishLaunchingWithOptions: you could present a modal view controller and perform your animation(s) inside of it then remove the controller.
Or you could perform those animations on the window.
Since the controller's view is inside a a tab bar controller, its view doesn't cover the tab bar and therefore cannot show over it.
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.
I have two view controllers myViewControllerA and myViewControllerB.
myViewControllerA has modalTransitionStyle = UIModalTransitionStyleFlipHorizontal.
Then I call presentModalViewController:animated: to load myViewControllerB. After calling dismissModalViewControllerAnimated:, suddenly all the views of myViewControllerA display shifted up by the height of the status bar.When I repeat the process, the views of myViewControllerA display properly once more.
So, the problems appears only upon the first call of the modal view controller. After dismissing and calling it again everything looks fine again.
What can cause this?
I know this is an old question, but it could still be helpful to someone.
The solution is so simple, its easy to pass it.
When you remove the simulated status bar of that view in Interface Builder, the frame still has a height of 460 (it should be 480, the height of the iphone screen)
Go to the Size tab (ruler icon), in the Attributes inspector, and set the frame to 480 again.
i need to shrink the height of a UINavigationBar (attached to the UINavigationController)
i've done this via the UINavigationControllerDelegate's navigationController:didShowViewController method, and it's working fine.
the problem is the visible viewcontroller that's in the main view. it wasn't resizing itself to reflect the new navbar height. thus, the didShowViewController method also resizes the viewcontroller's view frame, which works fine.
however, when i go to push on a new ViewController, or pop, i always see the view shift down to the original position during the animated transition to the next view. then, due to the code i have in the didShowViewController in the NavControllerDelegate, it shifts it back up.
i'm curious as to the best way to ensure that the shift down never happens.
i tried placing the code that resizes the frame into the willShowViewController, but that doesn't do anything.
i've also made sure that the UIView's frame that is the view of the UIViewController that's being popped, is also of the proper/shifted dimensions. no go there.
it's like i need to intercept the drawing actions after the pushViewController is invoked, and before the UINavigationController's didShowViewController is called.
i've been staring at my code for hours & hours... not getting anywhere. hopefully this makes sense to someone out there.
thanks!!!
Another option I think would be to set the NavigationControllers navigationBarHidden equal to YES. This will hide the nav bar completely and then you can then draw whatever view you want in the place the bar would have resided. Just put controls on the view that wrap the navigation methods (push, pop, etc...). It might be a challenge to get it to have the same style as a nav bar though.
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.