NAvigationbar jumping when loading view - iphone

I have implemented a container view controller (ios5) and now Im trying to implement custom animations/transitions for switching the view controllers.
But I have an issue when implementing any animation that involves a UINavigationController, the result is not as expected. For instance if I perform a flip from left animation when showing the controller with the navigation bar, the position for the navigation bar stays 44pxs below the original position and after the animation is performed the navigation bar will move smoothly to the original position which is really ugly...
This happens with every animation I perform, so I guess it has to be related only with the navigationcontroller.
This is the code I use for the flip transition
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:1.0
options:UIViewAnimationOptionTransitionNone
animations:^{
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:NO];
[UIView commitAnimations];
}
completion:^(BOOL finished) {
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];
I also tried the following
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
}
completion:^(BOOL finished) {
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];

Set the frame of navigation bar according iphone or ipad's and its orientation like this for portrait in iphone
[self.navigationController.navigationBar setFrame:CGRectMake(0, 20, 320, 44)]; //for iphone simarly for ipad and its orientation
You need to change your navigation bar frame to its actual position from status bar ie plus 20

I have similar problem with NavigationController and Container controller. Actually it was the toolbar at the bottom of window. My solution is to hide the toolbar first, then show toolbar with animation after the main transition completed. It looks like part of the whole animation.
Here is how I hide and show toolbar:
[toNavController setToolbarHidden:YES];
[self transitionFromViewController:fromViewController
toViewController:toNavController
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
}
completion:^(BOOL finished) {
[toNavController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
[toNavController setToolbarHidden:NO animated:YES];
}];

In viewDidLoad set frame.origin.y to 1. You still have a jumping but with 1 pixel.

Related

Animate a UIView change where the UIView is totally rebuilt

My UIViewController gets the view it is controlling to completely rebuild itself with something like this:
[self.view rebuildYourself:bIsLandscape]; // this line is in the ViewController
The view itself then contains the following method:
-(void)rebuildYourself:(BOOL)isLandscape
{
NSArray *viewsToRemove = [self subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
[self addControls]; // adds lots of views
[self layoutControlsWithOrientation:isLandscape]; // frames the views
}
I would like to animate the entire transition. I have tried this:
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.view rebuildYourself:bIsLandscape];
}
completion:^(BOOL finished){
}];
but the animation ignores the options value of UIViewAnimationOptionTransitionCurlUp and flows in from the top left corner every time.
and I have tried this:
[UIView beginAnimations:#"kkk" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDuration:1.0];
[self.view rebuildYourself:bIsLandscape];
[UIView commitAnimations];
but in this case the transition does curl up nicely but the underlying view is blank until the transition has finished, and then the new view suddenly 'pops' into view, which spoils the effect of the transition.
Can anyone tell me the right/best way to animate a transition where the view rebuilds itself completely?
Thanks
Make two views and put the old view overtop of the new re-built view. Then 'Curl-up' the old view so that the new view is showing and remove the old view from memory.

switch view with animation UIViewAnimationTransitionCurlUp

I am working on an iPad app which has a small popup view in front of the background main view.
The popup view displays one photo and its related notes etc. The main view is a bunch of thumbnails
I want to implement actions, like swipe left/right, to replace the popup view with a new popup view, with animation.
// popView is the existing pop up view to be replaced
MyPopupViewController *newPopView = [[MyPopupViewController alloc] initWithData:...];
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations: ^{
[self.view addSubView: newPopView.view];
[popView removeFromSuperView];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:popView cache:YES];
} completion:^(BOOL finished) { popView = newPopView }
];
[newPopView release];
Well, this doesn't work. I can't remove the old view in animation block otherwise the animation won't fire. I can't remove it in the completion block either, because during the animation, the old image will still be visible under itself.
I've spent quite some time playing with the sequences but just can't get it to work. Please help.
Thanks in advance.
Leo
I finally fixed this by setting the old view hidden in animation block. The animation will reveal the new view during animation.
Here is how I did: it works well in landscape an curls from bottom to top
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^()
{
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:self.welcomScreen cache:YES];
[self.welcomScreen setHidden:YES];
}completion:^(BOOL finished)
{
[self.welcomScreen removeFromSuperview];
}];

Movie not being shown right in landscape mode when using transitionFromView:toView:duration:options:completion but does when using addSubview

I have a movie for a landscape app, and when I just do [self.view addSubview:movieView], it works fine, but when I do transitionFromView:toView:duration:options:completion, it is displayed as if it's in portrait mode. Why is this, and how do I get trasitionFromView to work?
Without controller you can just use the existing view:
[UIView transitionWithView:fromView
duration:2
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[fromView addSubview:toView];
}
completion:NULL];
With transitionToView, you're replacing self.view at the top of the hierarchy, so movieView doesn't inherit the current bounds; i.e. it doesn't know it's in portrait mode. Try just animating the addSubView:
[UIView transitionWithView:self.view
duration:2
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.view addSubview:aViewController.view];
}
completion:NULL];

Flip animation when controller pushed on iPhone

I had a look around and didn't find what I was exactly looking for.
Is there a way to get a flip animation when pushing a view controller?
I read that you can change the animation by using a modal view controller but AFAIK the animation for a modal view is from bottom to top and that's not what i am looking for. Is there a way to get a flip animation somehow?
something like this should work
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController: yourviewcontroller animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
don't forget to set animated to NO when calling pushViewController
This also works.. for iOS 4.0 and greater
[UIView transitionWithView:self.navigationController.view duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
- (void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations]; }
in the new viewcontroller will make it flip back the same way (instead of sliding left) when the back button in the toolbar is pushed -- make sure animation is enabled here, e.g., if you make a custom button to pop the stack, use:
- (void) backToPrevious: (id) sender
{
//[self.navigationController popViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
}
For modally presented view controllers, you can change the animation with the modalTransitionStyle property. AFAIK, there is no way to change a navigation controller's push animation (except rebuilding UINavigationController from scratch).

Dismiss modalviewcontroller with a page curl

I am trying to dismiss a modalviewcontroller with a page curl. The curl works okay but I cannot seem to get the tableview under the modalviewcontroller to show up. The image of the modalviewcontroller is still under the curled away page. If I dismiss the modalviewcontoller before the animation finishes the animation doesn't show up. Here is my code:
//hide splash screen
- (void)hideSplash{
[UIView beginAnimations:nil context:nil];
//change to set the time
[UIView setAnimationDuration:2];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:modelView cache:NO];
// do your view swapping here
//[[self modalViewController] dismissModalViewControllerAnimated:NO];
[UIView commitAnimations];
//[self.view sendSubviewToBack:self.view];
}
Hope someone can help! Cheers Nick
In iOS4:
To present, it's something like:
[containerView addSubview:modelView];
[UIView transitionWithView:containerView
duration:.75
UIViewAnimationOptionTransitionCurlUp
animations:^{}
completion:^(BOOL finished) {
NSLog(#"finished %d", finished);
}];
To dismiss, use UIViewAnimationOptionTransitionCurlDown.
Your setAnimationTransition: shouldn't be forView:modelView; it should be for the parentView.
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:containerView cache:NO];
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
If you want to change the appearance
of a view during a transition—for
example, flip from one view to
another—then use a container view, an
instance of UIView, as follows:
Begin an animation block.
Set the
transition on the container view.
Remove the subview from the container
view.
Add the new subview to the
container view.
Commit the animation
block.
Use of this method is
discouraged in iOS 4.0 and later. You
should use the block-based animation
methods instead.