I can "curl up" a view controller with this code:
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController:page animated:NO];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
but I can't curl down the last page like this:
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController popViewControllerAnimated:NO];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
any idea why not? I just really want to "reverse" the animation (as if a sticker has been peeled off to show the 'push'ed view controller and stuck back on when they click a button).
Thanks
Ok, my old answer was totally wrong...
the problem is that you are popping the view controller before setting the transition view. If you change the code to this:
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
it works fine
Using OpenGL or a lot of complex CoreAnimation processes, I am sure that you could, but, It would be a lot of hassle for doing something like that. Something that might help you along: A simple book turning application written entirely with CoreAnimation
Related
I am using this code to change between 2 UIView:
UIViewAnimationOptions animationType = UIViewAnimationOptionTransitionFlipFromLeft;
[UIView transitionFromView:self.playlistTableView toView:self.playerView duration:0.5 options:animationType completion:^(BOOL finished){
[self.containerView sendSubviewToBack:self.upperView];
[self.containerView sendSubviewToBack:self.playerView];
self.isPlaylistVisible = !self.isPlaylistVisible;
isControlsHidden = NO;
}];
And i noticed a strange behavior, that when i made the flip the height of the self.playerView loosing 20px and after one second it's increase back to the normal frame size.
I try to change the animationType to UIViewAnimationOptionLayoutSubviews and now when i change between the view this behavior is not occur.
Any idea what can be the issue?
Please try this code.
[self.upperView setHidden:YES];
[self.playerView setHidden:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.playerView];
For getting reverse case
[self.upperView setHidden:NO];
[self.playerView setHidden:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.upperView];
I have a tabbar application with 4 tabs and a navigation bar hooked to one. On the tab with the navigation bar I have a button that brings you to a new page. I also have one that brings you back to the tab page, but I have a problem. When going back to the tab page the animation is going the wring way. I did this all with storyboards so no coding. I looked around and want to put this in the code:
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
But i have no idea how and where to put it in.
Take a look at this Apple guide to creating a custom segue. Your perform code would look something like this:
- (void)perform {
[UIView beginAnimations:nil context:NULL];
[self.sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
Then in your storyboard, set the type of the segue to Custom, and then enter the name of your custom segue class.
In my app I move a button with this code:
[UIView beginAnimations:#"timerView" context:nil];
[UIView setAnimationDuration:0.5];
[timerView setCenter:CGPointMake(967, 80)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
but I want that the animation decelerate first to arrive to the point, how can I do it?
Add this line,
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
I have developing project in iOS 6.0 sdk which should work on iOS4.3+ devices, in my project i am using the page curl to navigate betwwen pages , but the page curl happening in LandscapeLeft is not as same as Pagecurl in Landscape Right. I want the same page curl that is happening in Landscape Left to be in Landscape right.
Please take a look at the link for better understanding.
Video Demo Link
The code i have used is shown below
-(IBAction)nextBtnTapped {
UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
page2 *Obj=[[page2 alloc]init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
if (deviceOrientation==UIDeviceOrientationLandscapeLeft)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
else if(deviceOrientation==UIDeviceOrientationLandscapeRight)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:Obj animated:NO];
[UIView commitAnimations];
}
-(IBAction)prevBtnTapped {
UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
if (deviceOrientation==UIDeviceOrientationLandscapeLeft)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
else if(deviceOrientation==UIDeviceOrientationLandscapeRight)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:YES];
[UIView commitAnimations];
}
Can any one please tell me what wrong have i done in this code.
Any help will be appreciated.
UIDeviceOrientationLandscapeLeft with page curl is bugged. You won't get it to work correctly.
I am doing an animation, so when you click a button MyAccount from the first screen it will navigate you to Account View
- (void)pushToAccount
{
AccountViewController *controller = [[AccountViewController alloc] initWithNibName:#"AccountViewController" bundle:nil];
//[self.navigationController pushViewController:controller animated:NO];
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.view addSubview:controller.view];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView commitAnimations];
}
However, whenever i click on the Account View Controller ( contains some buttons and images view in it ), my program is crashing at it show EXC_BAD_ACCESS at main class
Please advice me on this issue...
Your view controller is trying to animate a transition by adding another view controller's view as a subview of your current view. That's problematic on a whole bunch of dimensions. Notably, you're not doing anything with the new view controller itself ... if this was an ARC project, it will get released on you.
If you just want to transition from one view controller to another, you should generally either do a standard pushViewController:animated: or presentModalViewController:animated:. It looks like you used to do the former. Why did you replace it with the current code?
If you can tell us what you were trying to do, why you're not using the standard transitions, perhaps we can help you further.
Update:
If you don't like the default animation, but rather want some custom animation to your transition, you can do something like:
CustomAnimationViewController *yourNewViewController = [[CustomAnimationViewController alloc] initWithNibName:#"CustomAnimationView" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:yourNewViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
// if you're using ARC, you don't need this following release, but if you're not using ARC, remember to release it
// [yourNewViewController release];
Update 2:
And, anticipating the logical follow-up question, how do you animate the dismissal of the new view controller, you might, for example have a "done" button that invokes a method like the following:
- (IBAction)doneButton:(id)sender
{
[UIView beginAnimations:nil context:nil];
[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];
}
My guess is that you have a UIButton that will call your pushToAccount method when pressed and that when it is pressed it cannot find that method. It coud be because the method signature does not include an object. So if you change your method from
- (void)pushToAccount
to
- (void)pushToAccount:(id)sender
It may fix your problem. It is also important to make sure that the object that contains the pushToAccount method isn't dealloc'd before that method is called. Perhaps put an NSLog message or a breakpoint inside dealloc to make sure it isn't called.
i think use bellow line
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];
insted of your bellow line..
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
hope this help you...
:)
and also for animation use bellow code if required....
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFromBottom];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
here use your view insted of window otherwise windows workfine..
:)