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.
Related
I have a custom segue, trying to replicate the push/pop segues of the pre iOS 7 style:
viewControllers animating SIDE-BY-SIDE, with NO darkening. (Is it really that hard!)
The code below works, except:
the exiting page becomes dark on exit
the entering page is dark on entering (gradually becomes normal as it moves into position)
These images illustrate the problem:
and then...
Is there a way to stop this darkening effect? I would be really grateful for some help.
-(void)perform
{
UIViewController *source = self.sourceViewController;
UIWindow *window = source.view.window;
CATransition *transition = [CATransition animation];
[transition setDuration:2.0];
[transition setDelegate:self];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[transition setType:#"push"];
[transition setSubtype:kCATransitionFromRight];
[window.layer addAnimation:transition forKey:kCATransition];
[window setRootViewController:self.destinationViewController];
}
These 2 functions work fine for me, although the code is pretty similar to yours, I hope it helps.
+(void) modalRight:(UIViewController*)vc destvc:(UIViewController*)viewCtrl{
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[vc.view.window.layer addAnimation:transition forKey:nil];
[vc presentModalViewController:viewCtrl animated:NO];
}
+(void) modalLeft:(UIViewController*)vc{
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[vc.view.window.layer addAnimation:transition forKey:nil];
[vc dismissModalViewControllerAnimated:NO];
}
I am coming from this question: How to change the Push and Pop animations in a navigation based app
I wanted to reverse the animation for push and pop. So that, instead of the default animating to Right, it should go to the Left and vice versa.
I created a subclass of UINavigationController and override the push and pop methods.
Here is the code:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:nil];
[super pushViewController:viewController animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:nil];
UIViewController *poppedVC = [super popViewControllerAnimated:NO];
return poppedVC;
}
So far, these are working perfectly.
In these methods, the line [self.view.layer addAnimation:transition forKey:nil]; is making me confused. I see that on every call to the methods a new CATransition object is initialized and added to the layer of the view. I am not sure whats the effect of this on memory. Is it safe and if not, what should I do so that it won't harm memory/performance?
An easy solution would be to add a CATransition ivar (or property) and reuse that every time. That said, I doubt this will affect performance noticeably and it's not usually useful to worry about performance until you've established that it is an issue.
So, in short, don't worry about it. If you ARE worried about it, make a single ivar that is used in each of these methods.
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.
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.
Right now when I use [self.navigationController setNavigationBarHidden:NO animated:YES];
The navigation bar flies in from right to left, is there a way to drop it down top to bottom?
Give this a go:
CATransition *transition = [CATransition animation];
transition.duration = kAnimationDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:tableViewController animated:YES];
Worked great for me.
Source: http://www.iphonedevsdk.com/forum/iphone-sdk-development/25045-navigation-controller-custom-animation.html