Reputation: 21
this is my first question so please go easy!!
I have an iOS app that has 5 tab bars, each of which contains a Navigation controller. It seems that no matter where I call presentViewController:animated:completion from, I get no animation from the transition, the presented view controller just appears on screen!
This is also happening with my UIImagePickerController that I am presenting from one of my tabs. No presenting animation, but when i dismiss it it DOES animate away!
Here is a sample of the code, sent from a code generated tab bar button, with its action hooked up to a method which simply does this..
UserRegistrationViewController *userRegistration = [[UserRegistrationViewController alloc] init];
userRegistration.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:userRegistration animated:YES completion:nil];
If anyone has ANY ideas of things that I could try I would be most grateful!
Upvotes: 2
Views: 1676
Reputation: 427
I'm assuming that you want your animation to occur during the transition between tab bar presses. If so, you have little control over that animation, as the tab bar manages the transitions for you. It looks like you're trying to achieve a cross fade between tab presses. Although you really can't fade out the old view controller, you can easily make the new view controller fade in when it appears:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Set the view to transparent before it appears.
[self.view setAlpha:0.0f];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//Make the view fade in. Set Opaque at the end for a performance boost.
[UIView animateWithDuration:0.5f
animations:^{
[self.view setAlpha:1.0f];
[self.view setOpaque:YES];
}];
}
Note that the tab bar is already presenting view controllers. You should not try to present the view controllers yourself. Let the tab bar manage this for you; that's what it's for.
Upvotes: 2