Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19802

Design for nonstandard navigation

I'm working on few views in an app that doesn't fit to any of standard Apple ViewControllers and I'm looking for a best solution for my problem.

Here is a quick mockup how it looks like:

http://pl.tinypic.com/r/2va1kbc/5

I have a main ViewController which is build of out 2 parts:
1. Top part which is always visible containing some logo
2. Content part which is changing - every content is a class (extending UIViewController)

Now tricky part is I want to do some animations in between of content changes - when user clicks a button on first one, top part slides down - pushing current viewController down, covers full screen and than slides up with a new viewController content.

So question is how to build it so it's easy to use and extend later (like UINavigationController).

I created a main view as UIViewController and added topView using:

 LogoUIViewController *logoViewController = [[LogoUIViewController alloc] init];
 [self.view addSubview:logoViewController.view];

 LoginViewController *loginViewController = [[LoginViewController alloc] init];
 loginViewController.delegate = self;
 [self.view addSubview:loginViewController.view];

I'm using delegate to initialize a transition on main view controller, because I couldn't find a better way of doing it.

But with that solution I stucked because of those problems:
1. How to make content view controller to only use part of screen (change it size) ?
2. How to animate those 2 views so it will look like top layer is pushing away content ?
3. How to exchange views in an easy way (like UINavigationController popViewController way) and initialize animation automatically between them.

I know those are 3 problems, but I think it can be solved with better way of constructing the main view controller. Does anyone have experience with custom navigation systems like that ?

Upvotes: 0

Views: 66

Answers (1)

danh
danh

Reputation: 62676

A UIPageViewController could be helpful. It would contain your content view controllers. The root vc that contains the page view controller can also be made it's delegate.

When you want to initiate a content view change, the root vc can do any animation it likes with it's page vc's view (like slide it down to reveal a larger header view). When the page transition is complete, as the delegate, the root vc can get notified with

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed

and then animate the restoration of it's view. Pretty simple, I think, and saves you a fair amount of effort on the container vc pattern. Xcode's default Paged App template is a really good starting point.

Upvotes: 1

Related Questions