Reputation: 29458
I'm familiar with the UITabBarController and UINavigationController paradigms where you present a new view controller for your different tabs, or push/pop a new view controller. What I am not familiar with, is an app like Flipboard. Flipboard will present me with a preview of 3 stories. If I tap on one of the stories, the transition I see is basically the story taking up the screen. In order to do something like this, I was wondering what kind of view hierarchy do you set up. My initial instinct is to have the views on top of each other and just hide and show one. The thing I don't like about this approach is it seems cluttered, especially if a lot of elements are on top of each other in IB. Is there a better way? Is it better to create a new viewController and do something like
- (IBAction)showDetailView:(id)sender {
[self.view addSubview:detailController.view]; // have the detailController.view as an ivar so we can reference it later
}
- (IBAction)removeDetailView:(id)sender {
[detailControllerIvar.view removeFromSuperview];
}
Sorry if this is a basic question. I'm not really familiar with situations where I don't just use a ViewController to show its own view by presenting it with a push/pop, tab press, show modal, etc. The addSubview I'm not really familiar with and didn't know if this was good or bad practice. Thanks!
Upvotes: 0
Views: 431
Reputation: 9561
You want to be using transitionFromViewController:toViewController
. It looks after the add/remove subview. Here would be an example...
[self addChildViewController:toViewController];
[fromViewController willMoveToParentViewController:nil];
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{}
completion:^(BOOL completed){
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];
}];
Upvotes: 1