Can anyone tell the block animation equivalent of this below code snippet?
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
NextViewController *next = [[NextViewController alloc]
initWithNibName:#"NextViewController" bundle:nil];
[self.navigationController pushViewController:next animated:YES];
[next release];
[UIView commitAnimations];
NextViewController *next = [[NextViewController alloc] initWithNibName:#"NextViewController" bundle:nil];
[UIView transitionWithView:self.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.navigationController pushViewController:next animated:NO];
}
completion:nil];
UIView: + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
Related
I am developing an App in Landscape Mode. While doing UIModalTransitionStyleFlipHorizontal flips in Landscape Mode, it flips Vertically.
Is there any way to fix it?
Here is the code:
InfoViewController *vc = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:vc animated:YES];
[vc release];
MyViewController *viewController = [[MyViewController alloc] init];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:viewController animated:NO];
[UIView commitAnimations];
[viewController release];
check this...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
I am trying to switch views, but I want the animation with the view lifts up and its like a piece of paper folding to see what is underneath.
Any tutorials or examples of how to get that view animation, if it is an animation, would be appreciated.
Actually the view that the maps app uses when you hit the button on the corner.
Something like this should work:
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
myView.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
navigation.modalTransitionStyle = UIModalTransitionStylePartialCurl;
navigation.delegate = self;
[self presentModalViewController:navigation animated:YES];
The key here is the modalTransitionStyle property needs to be set to UIModalTransitionStylePartialCurl before presenting the modal view.
More info here: UIViewController Class Reference (look for modalPresentationStyle, modalTransitionStyle, presentModalViewController:animated:, and dismissModalViewControllerAnimated:).
There are two basic ways of doing this, the old one which is no longer recommended:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:containerView cache:YES];
[containerView addSubview:subview];
[UIView commitAnimations];
And the new one (It uses blocks which are supported from iOS 4 and on):
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [containerView addSubview:subview]; }
completion:nil];
Sample on GitHub
I have a strange problem.
I have Navigation-based app with two UIViewControllers and Curl effect for transition between these.
I add to bar button and add custom action:
-(IBAction)pushPage
{
NSLog(#"push page");
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:secondView animated:NO];
[UIView commitAnimations];
[secondView release];
}
In SecondView I have a button with action:
-(IBAction)back
{
[imageAnimationIssueAppDelegate backPage];
}
Method backPage in AppDelegate:
-(void)backPage
{
NSLog(#"backPage");
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
[UIView commitAnimations];
}
PROBLEM:
On the RootView I have UIImageView with animation:
- (void)viewDidLoad
{
[super viewDidLoad];
animImage.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"2.png"],
nil];
animImage.animationDuration = 0.5;
animImage.animationRepeatCount = 0;
}
I start it in viewDidAppear:
- (void)viewDidAppear:(BOOL)animated
{
NSLog(#"First view - viewDidAppear");
[super viewDidAppear:animated];
[animImage startAnimating];
}
I stop it in viewDidDisapear:
- (void)viewDidDisappear:(BOOL)animated
{
NSLog(#"First view - viewDidDisappear");
[super viewDidDisappear:animated];
[animImage stopAnimating];
}
When I back from SecondView animation is stoped! But [animImage isAnimating] say YES!
It doesn't start witout update screen - you can click to button on the bottom and see it!
Is it bug?
Animation works without custom transitions.
When I set animated:YES for push or pop view, animation works with custom transitions between views.
Why?
Is there simple way to update displaying view to start animation?
I think you should have to write
[yellowBatterfly startAnimating];
in viewDidLoad method. and change method from
viewDidAppear to viewWillAppear and
viewDidDisappear to viewWillDisappear.
Hope It will works...
I think you have to perform the animations on the view using:
[UIView commitAnimations]
For some reason when I load a new view (from a .xib) it'll load the class files, BUT NOT the .xib!!
Here's my code:
login *lo =[[login alloc] initWithNibName:#"login" bundle:nil];
self.log = lo;
UIViewController *loginview = log;
[UIView setAnimationTransition:UIViewAnimationCurveEaseIn forView:self.view cache:YES];
[loginview viewWillAppear:YES];
[self.view removeFromSuperview];
[self viewWillDisappear:YES];
[self.view insertSubview:loginview.view atIndex:0];
[self viewDidDisappear:YES];
[loginview viewDidAppear:YES];
[UIView commitAnimations];
[log release];
Perhaps this question discusses what you're experiencing? Sorry if I misunderstood your question, it's kind of low on the details.
I am using the following code:
- (void)flip
{
MailComposerViewController *mailView = [[MailComposerViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:window
cache:YES];
[mtController.view removeFromSuperview];
//[self.window addSubview:[mailComposer view]];
[self presentModalViewController:mailView animated:YES];
[UIView commitAnimations];
[mailView release]
}
here mtController is a navigation controller (XIB file). I removed it and I add mailview, but the simulator does not show it. What am I doing wrong?
What are you trying to do? Less Vague Questions Is A Good Thing™. Are you trying to use a standard Mail compose controller and use it to flip over instead of present normally?
If so, you can do this:
MailComposerViewController *mailView = [[[MailComposerViewController alloc] init] autorelease];
mailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mailView animated:YES];