how can I animate the UINavigationBar background change on UIViewController push? - iphone

My app uses two different backgrounds for the UINavigationBar to indicate to the user what level in the hierarchy they're at. When I push a UIViewController that needs the second background it lacks animation, the background changes immediately as soon as the UIViewController is pushed. How can I animate this so that the background change fades as the view is being changed?

I know this is an old thread, but this worked for me:
CATransition *transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionFade;
transition.duration = 0.5;
[self.navigationController.navigationBar.layer addAnimation:transition forKey:nil];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed:#"navigationbar.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(44, 20, 44, 20)] forBarMetrics:UIBarMetricsDefault];
Place this inside your viewDidLoad method. You'll need to link/import the QuartzCore framework.

Related

How do you replicate a modal cross dissolve animation?

I have a game that has a replay button at the top of it. If you press the replay button the level restarts. Well, to accomplish this I used to do a segue from the button to its own vc, but i have been told thats bad because your just adding vc's to the stack when you dont have to.
So, i decided to just reset all the attributes, but I also want the cool cross disolve animation that you get when doing a modal segue. How can i add this?
you can try with animations in layer, for example:
CATransition *transition = [CATransition animation];
transition.duration = 2.0;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
self.view.hidden = YES;
self.view.hidden = NO;
this way every change you do in view will animate the view...

UIView animated swap views (slide down)

This is what i have so far. What I am trying to do is make the starting view (startUpView) to switch to the other view (creatNewGameViewController) by sliding down the screen with the new view. All it does now is switch views normally, but i really want that sliding effect. If anyone can spot the error in my code it would be much appreciated. Thanks
#import "CreateNewGameViewController.h"
#synthesize createNewGameViewController;
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
action:#selector(goToCreateGameViewController)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(65, 10, 190, 60);
-(void)goToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:#"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
CATransition *transition = [CATransition animation];
transition.duration = 2;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
CATransition *transition1 = [CATransition animation];
transition1.duration = 2;
transition1.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition1.type =kCATransitionMoveIn;
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[self presentModalViewController:newGame animated:NO];
[self.view insertSubview:newGame.view atIndex:0];
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
[newGame release];
UIView has a class method called transition from view to view animated, check if that helps and tell me how it was :)
UiView
one piece of advice, you should really be using a navigation controller, a storyboard or something like it to do that kind of view transitions because is the proper way to do.

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

Animate transitions between UIViews in a container view

I have a UIView that I use as a container for four separate subviews. At any one time, only one of the subviews is visible and the rest are hidden. Right now, when switching between the views, all I am working with is setting or inserting the hidden property.
I'd like to have some sort of an animated transition to give the app a bit more polish, but can't quite make sense of some of the other posts I've read.
Could someone walk me through how to animate transitions from one subviews to another within a containing UIView?
Thanks!
Try to read about transitionFromView:toView:duration:options:completion: here
Try playing around with this code. This must be very close to what you need.
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController popViewControllerAnimated:YES]
;

How to perform kCATransitionPush animation without any transparency / fade effects [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iPhone CATransition adds a fade to the start and end of any animation?
I'm trying to duplicate the "slide up from the bottom" animation that [UIViewController presentModalViewController:animated:] performs but without calling it because I don't want a modal view.
The below core animation code comes very close but appears to be changing transparency values of the views during it. At the start of the animation you can partially see through the view sliding up. By the middle/end of the animation the view we are sliding over is fully transparent so we can see behind it. I'd like both to remain fully opaque during this animation.
Any ideas on how to stop transparency changes in this code or to otherwise get the "slide up animation" I am looking for without requiring a modal view?
UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
The simplest method is to simply use UIView beginAnimations/commitAnimations block. You can adjust the duration and curve by reviewing the docs.
{
// Adjust for orientation as necessary.
view.frame = CGRectMake(0,
-480,
320,
480);
[UIView beginAnimations:nil context:nil];
view.frame = CGRectMake(view.frame.origin.x,
0,
view.frame.size.width,
view.frame.size.height);
[UIView commitAnimations];
}
Docs here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
Instead of the CATransition, you could instead try using a CABasicAnimation that animates the position from off the top of the screen into the desired position.