Changing the animation for UINavigationController NavigationBar - iphone

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

Related

CATransition for segue animation (pre iOS 7 style)

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];
}

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.

switch two view controller's view in a cube animation

the code below implement the switch between two view in a cube animation .
UIViewController* viewCtrl = [[UIViewController alloc] init:book];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube";
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];
but, if the view don't belong to self.navigationController, how to do switch in cube animation between two view controller, and then how to scale the current view controller's view in the same time? thanks very much
This worked for me:
-(IBAction)animate:(id)sender {
NSLog(#"animate");
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 0.8;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[0];
transition.subtype = subtypes[1];
[self.view.layer addAnimation:transition forKey:nil];
SecondView *_secondViewController = [[SecondView alloc]initWithNibName:#"secondView" bundle:nil];
self.secondViewController = _secondViewController;
_secondViewController = nil;
[[[self view] layer] addAnimation: transition forKey: nil];
[[self view] addSubview: [self.secondViewController view]];
}
-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
[self.view release];
}

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.

FlipFromRight UIView animation

First here's my code:
[_helperView addSubview:_navigationController.view];
[_helperView addSubview:itemView];
[UIView beginAnimations:#"pageFlipAnimation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_helperView cache:NO];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(pageFlipAnimationDidStop)];
[itemView removeFromSuperview];
[UIView commitAnimations];
My problem with this that nothing is animated. If I add the _navigationController.view and itemView before (I mean not in this method) everything is ok, but when I add before the animation it does nothing. I also tried to call again the animation in the animation didStopSelector and also works there.
Can you help me please why it doesn't want to work in this case? Any suggestions how to resolve it?
You should probably give the UI the chance to effectuate the addition of itemView. To do this, add a line after addSubview:itemView:
[self performSelector(removeAnim:) withObject:itemView afterDelay:0.01];
and move the animation block to a function
-(void)removeAnim:(UIVieW*)itemView
This should fix the problem.
Use QuartzCore.framework With these animations.
-(void)viewSlideInFromRightToLeft:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromRight;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromLeftToRight:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromLeft;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromTopToBottom:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromBottom ;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromBottomToTop:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromTop ;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
For AnimationType you can use following option:-> kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade
For AnimationSubType you can use following option:-> kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom