开发者

How to simulate the behavior of a UITabBarViewController?

I want to duplicate this controller same functionality without using it, this is because tab bar controllers are not customizable at all (fixed size, toggleable state tabs, etc...).

I want a customized "tab bar" that contains whichever view I want. And also开发者_高级运维 I need to push view controllers leaving this customized tab bar fixed in its position.

I´ve seen lots off apps that do this, and I was wondering if using different UIWindow objects (one for the custom tab bar and other one for the content) was the best approach.

Any advice or guidance on this?

Thanks in advance.


Definitely not UIWindows - in an iPhone app there should only ever be one UIWindow.

I'd make a UIViewController subclass that had your new navigation bar ui at the top and a UIView underneath it. This view would be used to contain all the views of the controllers you are going to push in it. The view would have clipsToBounds set to YES to make sure your other controllers views don't overlap your navigation bar etc.

It would also have an array to hold the list of controllers that are currently inside it.

Your controller would implement the pushViewController:animated: methods etc to allow you to add other view controllers to the stack - you would add the new controller to your array and would add it's view as a subview of your controller's view.

However, it's actually quite a lot of work to make this well - a navigation controller will release child controller views on low memory warnings, handle rotation, animating on/off views etc. Are you 100% sure that this is what you want to do?


I've used a very simple approach. I subclass UITabbarController and during the init:

    //  Custom TabBar View
    //
    self.tabBar.hidden = YES;
    MyTabBarView *myTabBarView = [[MyTabBarView alloc] initWithFrame:CGRectMake(0, 1024-44, 768, 44) // it'a an iPad app
                                                       configuration:configuration]; // an array of dictionary representing the view controllers
    [self.view addSubview:myTabBarView];
    [bottomBarView release];

then I load some view controllers with:

aViewController.hidesBottomBarWhenPushed = YES; 

From MyTabBarView instance I perform on the UITabBarViewController:

setSelectedIndex:

In this way I've a customizable full screen application without pains.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜