Reputation: 31
I have a UINavigationController that has a visible Navigation Bar and Toolbar. When pushing a controller (the same controller), I want to only animate the content portion (with a sliding effect for example), and keep the NavigationBar and Toolbar unanimated/constant. Can anyone offer any suggestions on a clean way of doing this? Thanks.
Upvotes: 2
Views: 6172
Reputation: 4185
Set the navigationItem of the new UIViewController to be the same as the current UIViewController.
newViewcontroller.navigationItem = self.navigationItem;
[self.navigationController pushViewController:recallViewController animated:YES];
Upvotes: 0
Reputation: 4555
Try adding the toolbar as a subview to window instead of View. and restrict the navigationcontroller view height so that it toolbar will be visible to you. Now if you push the view controller, Navigation bar and Toolbar will remain unanimated/stagnent.
Upvotes: 1
Reputation: 7469
I'd move the views manually and animate them using a animation block:
// Get position of old view controller
CGPoint center = [oldViewController.view center];
// Position new view controller to the right of old one
[newViewController.view setCenter:CGPointMake(center.x + 320, center.y)];
// Animate change
[UIView beginAnimations:@"myAnimation" context:NULL];
// Move old view off screen
[oldViewController.view setCenter:CGPointMake(center.x - 320, center.y)];
// Move new view onto screen
[newViewController.view setCenter:center];
// Set animation delegate to self so that we can detect when animation is complete
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationComplete:finished:target:)];
// Finish animation block
[UIView commitAnimations];
If you need to actually push the new viewcontroller using the navigation controller you need to make sure you do this after the animation has finished otherwise the old view will not be displayed. To do so you need to use the setAnimationDelegate method to get notified of when the animation is complete and pass in a selector method to be called. Implement the above code and the following method in the same class:
(void)animationComplete:(NSString *)animationId
finished:(BOOL)finished
target:(UIView *)target
{
if([animationId isEqualToString:@"myAnimation"])
{
// Push viewcontroller here
}
}
Upvotes: 1