How to associate full page curl animation for modalviewcontroller? - iphone

Currently I am showing a modal view controller for some info .
I want to show or hide the modal view controller with full page curl animation .
Currently I am showing this modal view controller from one of the view controller of the tab bar controller .
I have the option of partialpagecurl in the modalTransitionStyle property of the modalviewcontroller to be displayed .
Current code :
InfoViewController *infoViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:[NSBundle mainBundle]];
//infoViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:infoViewController animated:YES];
[infoViewController release];
So How can I associate a full page curl transition or animation with a modalviewcontroller .
Thanks .

[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDuration:0.5];
[UIView commitAnimations];

Keep the following code in viewDidAppear and viewWillDisappear calls in the view controller you want to present as modal
[UIView transitionWithView:self.view.window
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^(void) {
}
completion:^(BOOL finished) {
if (true == finished) {
}
}];
You can keep an extra flag in viewcontroller class so that you can enable/disable the page curl as required.

Related

UIView animation transition between views

I need to make an animation that will come in from the right, displaying the new view.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelay:.5f];
[UIView setAnimationDuration:0.5f];
// display view controller
[UIView commitAnimations];
What should I add here??
IF you have navigationController then use
NextViewcontroller *nextView = [NextViewcontroller alloc]initWithNibName#"NextViewcontroller"
bundle:nil];
[self.navigationController pushViewcontroller:nextView animated:YES];
[nextView release];
How about adding the view as a subView to your current view, then set its place to be outside the current visible area. After which you set your animation to change your subViews position to overlap the current view.

horizontal flip animation on modal UIView

how can i present a modal view with an horizontal flip animation (like pushing an view controller on a navigation controller) ?
i tried this but it doesn't work
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[self presentModalViewController:detailsViewController animated:NO];
[UIView commitAnimations];
thanks !
This is all you need:
detailsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:detailsViewController animated:YES];

Flipping a UIViewController managed by a UINavigationController hides navigation bar

I'm 2 levels down on a UINavigationContoller having already pushed a few views. Now I'm looking at an image inside one of the pushed view controllers and when I tap an info button in the navigation bar, I want the sub view to flip leaving the nav bar in place. How do I get just the subview (the view that was pushed) to flip? Right now the nav bar also flips and prevents me from navigating back up my stack.
-(void)showImageInfo
{
self.imgInfoViewController = [[ImageInfoViewController alloc] initWithNibName:#"ImageInfoViewController" bundle:nil];
[self.imgInfoViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self.navigationController presentModalViewController:self.imgInfoViewController animated:YES];
}
code from UICatalog Example.... I think it will do what you are looking for. Basically you have to do some more coding to get the flip behavior.
http://developer.apple.com/iphone/library/samplecode/UICatalog/Listings/TransitionViewController_m.html#//apple_ref/doc/uid/DTS40007710-TransitionViewController_m-DontLinkElementID_34
- (IBAction)flipAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:kTransitionDuration];
[UIView setAnimationTransition:([self.mainView superview] ? UIViewAnimationTransitionFlipFromLeft :UIViewAnimationTransitionFlipFromRight) forView:self.containerView cache:YES];
if ([flipToView superview])
{
[self.flipToView removeFromSuperview];
[self.containerView addSubview:mainView];
}
else
{
[self.mainView removeFromSuperview];
[self.containerView addSubview:flipToView];
}
[UIView commitAnimations];
}

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).

Flip View Iphone

please consider the code below, and tell me what I'm doing wrong.
I want to flip between two UIViews.
Somehow, when I flip away from the initial view, I just get the flipped view, without animation. When I flip back, the animation shows just fine.
The flips are triggered from buttons on the views themselves.
- (IBAction)showMoreInfo:(id)sender
{
UIView *moreInfo = self.flipView;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
[parent addSubview:moreInfo];
[UIView commitAnimations];
}
- (IBAction)showLessInfo:(id)sender
{
UIView *lessInfo = self.view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.flipView cache:YES];
UIView *parent = self.flipView.superview;
[self.flipView removeFromSuperview];
[parent addSubview:lessInfo];
[UIView commitAnimations];
}
It's probably because you aren't using a container view as the transition view. Refer to the documentation on setAnimationTransition:forView:cache:
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.
Try using self.view.superview in the animation transition view of the showMoreInfo:
The reason the showLessInfo: method works is you are using a container view.
Can you use your MainWindow (UIWindow) as the container view as UIWindow inherence from UIView?
Also iPhone 3.0 introduced the flip transaction via the presentModalViewController method:
CustomViewController *vc = [[CustomViewController alloc]
initWithNibName:#"CustomViewController" bundle:nil];
vc.delegate = self;
// The magic statement. This will flip from right to left.
// present the modal view controller then when you dismissModalViewController
// it will transition flip from left to right. Simple and elegant.
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:vc animated:YES];
[vc release];
After iOS 4.0, you can flip between views with this:
[UIView transitionFromView:sourceView toView:destinationView duration:0.35f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
NSLog(#"I just flipped!");
}];
As Jason mentioned, you'll need this to occur within a container view.