Push view controller with custom page curl animation - iphone

I want page curl like animation when I push another view. I don't need the default one.
Can I push view with custom animation? I have image sequence.
How can we do that? Help me, please!

You can do this using QuartzCore framwork.
first, #import and before push view controller add this code.
Hope you are OK!
YourViewController *viewControlle = [[YourViewController alloc] init];
CATransition* transition = [CATransition animation];
transition.duration = 1.0;
transition.type = #"pageUnCurl";
transition.subtype = kCATransitionFromRight;
transition.timingFunction = UIViewAnimationCurveEaseInOut;
[self.navigationController.view.layer
addAnimation:transition forKey:kCATransition];
[self.navigationController
pushViewController:viewControlle animated:NO];

Related

PushViewController to the left - Simple?

I'm trying to get my ViewController to slide from Left to Right at the same speed as the standard PushViewConrtoller, I'm not using a NavBar and don't want to use Modal, is there a simple way to do this, I've seen a lot of variations on different threads, but none of them work correctly!
I'm using a Navigation Controller with the following code for my Push right...
- (IBAction)launch1990:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"1990"];
[self.navigationController pushViewController:vc animated:YES];
}
UIStroryBoard when you push view controllers, or segues, it doesn't let you customize too much. What I ended up doing was override the perform method and used QuartzCore Animations to customize our transitions. I subclassed UIStoryBoardSegue and overwrote the perform function.
Below to customize for Push or Pop then for Segues. (For segues remember to change the class to the custom class in IB).
To do it from a normal pop or push (this does cross fade animation, adjust it for yours):
#import <QuartzCore/QuartzCore.h>
- (IBAction)launch1990:(id)sender {
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"1990"];
[self.navigationController pushViewController:vc animated:NO];
}
To do it from segue:
//ZHCustomSegue.h
#import <Foundation/Foundation.h>
#interface ZHCustomSegue : UIStoryboardSegue
#end
// ZHCustomSegue.m
#import "ZHCustomSegue.h"
#import "QuartzCore/QuartzCore.h"
#implementation ZHCustomSegue
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}
#end
Use CATransition with subtype: kCATransitionFromLeft
CATransition *transition = [CATransition animation];
transition.duration = .3;
transition.type = kCATransitionMoveIn;
transition.subtype= kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
Do the normal navigation vc push, but beforehand:
vc.navigationBar.hidden = YES;

iphone - UIImagePickerController... making it appear from the right

I have to present a UIImagePickerController but when I do so, it always come from the bottom up. Is there a way to make it appear from the right to left?
I have tried this without success:
CATransition* transition = [CATransition animation];
transition.duration = 0.35f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController presentModalViewController:picker animated:YES];
thanks
I assume you are currently displaying the picker by calling presentModalViewController:animated: and passing YES as the animated option.
What you can do instead is present without animating, and instead cover the appearance using your own transition animation. The example below would present from the right:
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentModalViewController:pickerController animated:NO];
To use this you'll need to #import <QuartzCore/QuartzCore.h> and add the QuartzCore framework to the project.

iPhone: changing CATransition causes UIActivityIndicatorView to stop animating

I have implemented a non-default animation for when a new view is pushed onto the screen (see code below). For some reason once I implemented this code it caused my UIActivityIndicatorViews to stop working. They will been shown on the screen but not animate even when their isAnimating is true. I figure it is because of me changing the CATransition, but can't figure out how to fix it for the UIActivityIndicatorView.
change default animation for push
CATransition* fade = [CATransition animation];
fade.duration = 1.0;
fade.type = kCATransitionFade;
fade.subtype = kCATransitionFromTop;
[self.navigationController.view.layer
addAnimation:fade forKey:kCATransition];
later on in viewDidLoad I start the animation
[spinner startAnimating];
but the spinner will show and not animate. For some reason the very first spinner I have animates but after that nothing.
I was encountering this problem when using a CATransition inside a subclass of UINavigationController to have a custom animation when pushing or popping view controllers.
Inside a method of this UINavigationController's subclass I had this code:
- (void)addCustomTransition
{
CATransition* transition = [CATransition animation];
transition.duration = kAnimationDuration;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.view.layer addAnimation:transition forKey:nil];
}
However, I later found out you also have to add the same animation to the pushed/popped viewController's view's layer:
- (void)addCustomTransitionToViewController:(UIViewController *)viewController
{
CATransition* transition = [CATransition animation];
transition.duration = kAnimationDuration;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.view.layer addAnimation:transition forKey:nil];
[viewController.view.layer addAnimation:transition forKey:nil]; // this is what was missing
}
This pushed/popped view controller's view is that one that had an UIActivityIndicatorView that wasn't animating properly.
Hope this helps!
just change your time duration from 1.0 to 0.3 or less
just i am tested and it's working

Custom UIViewAnimationTransition on iPad

I'm wondering if there is any chance to create a custom transition animation between Views, as a "cube":
http://www.pendrivelinux.com/wp-content/uploads/pdl-cubed.jpg
I've took a look for some example, without any success, do you know some, is even possible?
Thanks
UIViewController* viewCtrl = [[UIViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube"; //Note: undocumented API, will probably cause App Store rejection
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
It should be possible. You will need to have 2 views and a bit of Core Animation 3D transforms.

Using CATransition's In Three20?

I am looking to implement CATransitions within TTNavigator, I know the method
openURL can take a UIViewAnimationTransition but that only gives me
flipping and curling animations, but with CATransition I have access
to another 8, of which kCATransitionFromRight, kCATransitionFromLeft,
kCATransitionFromTop, kCATransitionFromBottom are the ones I am
specifically after.
With a UINavigationController would use something like this piece of code to
give me more control over the animation:
CATransition *transition = [CATransition animation];
transition.duration = 0.5f;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
[self.navigationController.view.layer addAnimation:transition
forKey:nil];
This code however, doesn't work with TTNavigator. Does anybody know
how I can get my own custom animations to work with TTNavigator? Or if
I am doing something wrong in my code?
Turns out i answered my own question, but rather than using that last line of code to set the animation on the navigationController i was trying to set the transition to the URLAction. Once i put that line back in and commented out the URLAction transition code it seems to work!
// create the URLAction
TTURLAction* urlAction;
urlAction = [TTURLAction actionWithURLPath:#"tt://Images"];
[urlAction applyAnimated:YES];
// create the CATransition and set it to the navigation controller
CATransition *transition = [CATransition animation];
transition.duration = 0.5f;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
[self.navigationController.view.layer addAnimation:transition
forKey:nil];
// tell the navigator to run the action
[[TTNavigator navigator] openURLAction:urlAction];
Hope this helps someone else in the future!
You can easily add flip or any other kind of animation on TTNavigator using TTLauncherView as follows:
- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item {
TTURLAction* action = [TTURLAction actionWithURLPath:item.URL];
[action setAnimated:YES];
[action setTransition:UIViewAnimationTransitionFlipFromLeft];
[[TTNavigator navigator] openURLAction:action];
}
This makes TTNavigator use animated transition while displaying new URL.