popViewController doesnt seem to work with UIView animations - iphone

I have the following code, which does a nice animation when pushing a new view controller.
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:0.5];
[[self navigationController] pushViewController:details animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
This code, using popViewController (rather than pushViewController) doesnt do the animation.
[UIView beginAnimations:#"animationback" context:nil];
[UIView setAnimationDuration:0.5];
[[self navigationController] popViewControllerAnimated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Any ideas why this would be and more importantly; how can I fix it?

Are you sure that self.navigationController.view really refers to the right view ... the one being animated? I have the feeling that the first case works only by accident. Shouldn't you refer to the view of the controller being pushed / popped?

Related

iphone dev: how to control the view transition animation?

I am using such code to present a new view, I don't it's good or not. Currently the default animation is show the view from bottom up, but i want it to animate from right to left(fly in), is it possible to change the default animation type and how? Thanks.
[self presentModalViewController:navController animated:animated];
You can disable the slide-up animation like this:
[self presentModalViewController:navController animated:NO];
Then you can provide your own animation code:
navController.view.frame = CGRectMake(320, 0, navController.view.frame.size.width, navController.view.frame.size.height);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
navController.view.frame = CGRectMake(0, 0, navController.view.frame.size.width, navController.view.frame.size.height);
[UIView commitAnimations];
This example gives you the "Fly-in" from right with a smooth speed-curve.
Another way is using the built in slide-in from right with navigationcontroller:
[self.navigationController pushViewController:navController animated:YES];
In this one, your top-viewcontroller needs to be a UINavigationController and it's rootcontroller needs to be your viewcontroller. Then you can push other viewcontrollers.
I have done this and its working for me try ths:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.View2.superview cache:YES];
[self.View2 removeFromSuperview];
[self performSelector:#selector(replaceViews2) withObject:nil afterDelay:0.6];
[UIView commitAnimations];

navigate to new page in iPhone

I am new to iPhone developer,
On click of button, i want to navigate to a new page with this animation, UIViewAnimationTransitionFlipFromLeft
How should i do this ?
-(void)btnClick{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[UIView commitAnimations];
}
When i click on btn Animation happens but i am unable to navigate to new page.
Any Help Will be Appriciated !
ViewController *viewController = [[ViewController alloc]initWithNibName:#"View" bundle:nil];
[UIView beginAnimations:#"Flip" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView commitAnimations];
[viewController release];
viewController is the page u want to navigate to.
Pop:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
You aren't specifying which views you want to swap in and out. At the moment you are just setting where the animation happens and what type of animation it is.
You need something like this.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[view1 removeFromSuperview];
[self.view addSubview view2];
[UIView commitAnimations];
I recommend reading this documentation as I dont think you understand the ViewController and View relationship entirely. There are different ways of transitioning between ViewControllers and individual views.
Just in the case of using this method your view1 would be LicAppViewController.view and assuming you PlanPage is a view then view2 is just PlanPage.

Change between UIViewcontroller.view subviews with animation

I have one view controller which contains two views (redView, blueView). The views are smaller than the main view.
I want to change from redView to blueView with animation. If use this none animation happens.
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:redView cache:YES]; // !!! I WILL CHANGE THIS
[self.view addSubview:blueView];
[redView removeFromSuperview];
[UIView commitAnimations];
In case I change the code to this, then the animation is ok but the whole mainView animates, something that i do not want to happen. I want only the subViews to flip. I should note that the 2 subviews are in the same position. (frame) Any ideas?
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[self.view addSubview:blueView];
[redView removeFromSuperview];
[UIView commitAnimations];
Use Block animation instead of simple animation, from apple about simple animation "Use of the methods in this section is discouraged in iOS 4 and later"
Animation With Block's
[UIView transitionWithView:containerView
duration:1.25
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^
{
[redView removeFromSuperview];
[containerView addSubview:blueView];
}
completion:NULL];
containerView : is main view that will be animated.
Also add to your containerView redView,
that all :)
for more info look at
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Solution Found:
I use a tempView for which i do the animation. Onto the tempView I add view1 and view2.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:tempView cache:YES];
[tempView addSubview:view2];
[view1 removeFromSuperview];
[UIView commitAnimations];
Extra: For a better animation you can use view1.visible = YES , NO instead of addSubview, removeFromSuperView, but they will be allocated all the time
In your first example it looks like you are deleting the redView before it can animate, try deleting it after the animation.
Code:
[UIView setAnimationDidStopSelector:#selector(removeRedViewFromSuperview)];

how to go one view from another view using with flip animation in iPhone

I am flip animation to go from one view to another and animation is working properly but when i am using button action on that view that time application is getting crash.
Please help me out to solve this problem.
my code is:
Abtsk1 *secondViewController = [[Abtsk1 alloc]
initWithNibName:#"Abtsk1"
bundle:nil];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:[[self navigationController] view] cache:YES];
[self.view addSubview:secondViewController.view];
[UIView commitAnimations];
Thanks
Kunal

how can I get animation when going to previous view

i have used viewcontroller with multiple view.
when i go back to previous, there is no animation
i have tried by below lines of code ,
-(IBAction)goback
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
You can't animate a method call. You can only animate properties of the view such as frame, size, alpha etc. removeFromSuperview isn't a property, it is a method that simply finds the superview and removes the originating view from the array of subviews.
You need to run the animation and then send removeFromSuperview when the animation completes.
use below code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];