iPhone:Animation move view controller upward - iphone

I am developing an iPhone application, where i need to move a first view controller slowly upward in animation and move to second view controller. I am thinking to use CoreAnimation for moving the first view controller slowly upward and push to next view controller. Could someone help on giving what are the classes/apis available to achieve this?
Thank you!

Try this,
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yourfirstview cache:YES];
[UIView setAnimationDidStopSelector:#selector(remove_view)];
//change frame here
yourfirstview.frame =CGRectMake(0,-480,320,480);
[UIView commitAnimations];
-(void)remove_view
{
[yourfirstview removeFromSuperview];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yoursecondview cache:YES];
//change frame here
yoursecondview.frame =CGRectMake(0,0,320,480);
[UIView commitAnimations];
}

You can easily achieve this on a single view controller using multiple UIViews
As per Apple's documentation:
In iOS 4 and later, use the block-based animation methods.
So, in order to produce the intended results, using the following code.
UIView *mySecondView = [[UIView alloc] initWithFrame:CGRectMake(0, 480, 320, 480)];
[mySecondView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:mySecondView];
[UIView animateWithDuration:2.0 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[mySecondView setTransform:CGAffineTransformMakeTranslation(0, -480)];
}completion:^(BOOL done){
}];

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];

Looking for a within app transition (revolving screen effect)

I want a transition within my app that is like the mystery revolving wall from old scooby doo cartoons. I want the screen to revolve when switching views. Anyone point me in the right direction for the possibility of accomplishing this?
Or this, which uses far less ink:
UIView *bookCaseView; // this is the container... the haunted wall
UIView *booksView; // just an ordinary set of books, right?
UIView *spookyBackside; // ruh-roh, raggy!
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[booksView removeFromSuperview];
[bookCaseView addSubview:spookyBackside]; }
completion:NULL];
I think this is what you are looking for:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//optional if you want to do something after the animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myAnimationDidFinish:finished:context:)];
//
[view2 setFrame:CGRectMake(0, 0, view2.frame.size.width, view2.frame.size.height)];
[view1 addSubview:view2];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view1 cache:YES];
[UIView commitAnimations];
And to flip back:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//optional if you want to do something after the animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myOtherAnimationDidFinish:finished:context:)];
//
[view2 removeFromSuperview];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1 cache:YES];
[UIView commitAnimations];

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)];

UIView Animation isn't working

[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:0.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewHelp cache:YES];
[self.view addSubview:viewHelp];
[UIView commitAnimations];
Where am I doing wrong? I am able to switch the view but I am not able to animate it.
[self.view addSubview:viewHelp]; the animation is just literally adding the subview, you need to work out what animation you want, and then apply it by changing values in the views frame property.?
follow this thread : click me

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];