navigate to new page in iPhone - 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.

Related

Flip Right UIView1 to UIView2

I have two UIViews VW1 and VW2 in the same UIViewController.
I'm trying to flip to the right from VW1 to VW2 and using the following code that I don't know how and where to call the method?
-(void)FlipFromRight
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2 cache:YES];
[UIView commitAnimations];
}
Above code is not working for me.
You need to do :
if ([VW1 superview])
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aTableBGView cache:NO];
[VW1 removeFromSuperview];
[mainView addSubview:VW2];
[mainView sendSubviewToBack:VW1];
}
else
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aTableBGView cache:NO];
[[mainView viewWithTag:2001] removeFromSuperview]; // VW2's tag ID
[mainView addSubview: VW1];
[mainView sendSubviewToBack: VW2];
}
[UIView commitAnimations];
here add one uIButton like name "btnSwipe" on navigationbar or on the MainViewcontroller and after that just give the button title for example i.e "Left".
after that give the action event with this bellow method
-(IBAction)FlipFromRight:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
if ([btnSwipe.titleLabel.text isEqualToString:#"Left"])
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:uiView1 cache:YES];
[btnDraw setTitle:#"Right" forState:UIControlStateNormal];
}
else{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2 cache:YES];
[btnDraw setTitle:#"Left" forState:UIControlStateNormal];
}
[UIView commitAnimations];
}
here just give the IBAction from xib to btnSwipe and it will work
i hope this is useful to you..
:)

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

popViewController doesnt seem to work with UIView animations

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?

Flip between Image 1, 2, 3 instead of Image 1,3 (iPhone SDK)

I'm using some pretty standard code to flip 2 UIImageViews that are inside a small view.
(I'm amazed it worked!)
But what if I had THREE UIImageViews inside a small view... and wanted to flip between all 3?
I thought I could just cut/paste 2 copies of my code... but I guess not.
When I try to flip 1>2.. and then 2>3... it just flips once... going directly from 1>3.
What happened to 2????
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
The animations are not chained together like this. Basically, they are doing both animations at the same time. What you want is to create a new method for the second flip that will be called after the first one is done:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)contextn {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
}
Then in your existing method, put this line:
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
like so:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
For more info, check the apple docs
You could set a 0.5 second delay on the start of the second animation.
Also, you may want to check out keyframe animations to do more advanced stuff like this.
Jill,
In your second code block, do the following.
[UIView beginAnimations:nil context:NULL];
// This will cause your second animation block to wait 0.5 second, which will be
// enough time for the second one to kick in and do it's thing.
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];