如何模拟 UITabBarViewController 的行为?

发布于 2024-10-05 14:56:37 字数 237 浏览 1 评论 0原文

我想复制此控制器相同的功能而不使用它,这是因为选项卡栏控制器根本不可自定义(固定大小、可切换状态选项卡等)。

我想要一个自定义的“选项卡栏”,其中包含我想要的任何视图。而且我还需要推动视图控制器,使这个自定义选项卡栏固定在其位置。

我见过很多这样做的应用程序,我想知道使用不同的 UIWindow 对象(一个用于自定义选项卡栏,另一个用于内容)是否是最好的方法。

对此有何建议或指导?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝在阴天搁浅。 2024-10-12 14:56:37

绝对不是 UIWindows - 在 iPhone 应用程序中应该只有一个 UIWindow。

我将创建一个 UIViewController 子类,它的新导航栏 ui 位于顶部,而 UIView 位于其下方。该视图将用于包含您要推入其中的控制器的所有视图。该视图会将 ClipsToBounds 设置为 YES,以确保其他控制器视图不会与导航栏等重叠。

它还会有一个数组来保存当前位于其中的控制器列表。

您的控制器将实现 PushViewController:animated: 方法等,以允许您将其他视图控制器添加到堆栈中 - 您可以将新控制器添加到数组中,并将其视图添加为控制器视图的子视图。

然而,要做好这一点实际上需要做很多工作 - 导航控制器将在内存不足警告时释放子控制器视图、手柄旋转、动画开/关视图等。您是否 100% 确定这就是您想要做的?

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?

时光与爱终年不遇 2024-10-12 14:56:37

我使用了一种非常简单的方法。我对 UITabbarController 进行子类化,并在 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];

然后我加载一些视图控制器:

aViewController.hidesBottomBarWhenPushed = YES; 

从 MyTabBarView 实例中,我在 UITabBarViewController 上执行:

setSelectedIndex:

通过这种方式,我可以轻松创建一个可自定义的全屏应用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文