在标签栏控制器/导航控制器上方添加自定义视图? [英] Adding custom view above tab bar controller/navigation controller?

查看:30
本文介绍了在标签栏控制器/导航控制器上方添加自定义视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码,试图让自定义视图显示在选项卡栏控制器(它的所有选项卡中恰好有一个导航控制器)上方.

I tried the following code, in an attempt to get the custom view displaying above the tab bar controller (which happens to have a navigation controller within all of it's tabs).

问题是它覆盖在导航栏的顶部,我希望导航栏向下移动.

The problem is that it overlays on top of the navigation bar, and I want the navigation bar to be moved down.

我尝试设置标签栏控制器的框架,但根本没有移动它.

I tried setting the frame of the tab bar controller, but that didn't move it at all.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window
    //self.tabBarController.view.frame = CGRectMake(0, 62, 320, 320);
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    // setting up the header view
    self.headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0, 20, 320, 42)];
    [self.window addSubview:self.headerView];

    // setting up facebook stuff
    AgentSingleton *agentSingleton = [AgentSingleton sharedSingleton];
    agentSingleton.facebook = [[Facebook alloc] initWithAppId:APP_ID];

    return YES;
}

有什么想法吗?

推荐答案

确实没有什么好的方法可以做到这一点.UINavigationController 和 UITabBarController 的各种子视图都是私有的,试图弄乱它们很可能无法正常工作.而且 Apple 没有给我们提供创建容器"视图控制器的工具,因此您无法轻松地将 UINavigationController/UITabBarController 嵌入另一个视图控制器中或自己重新创建 UINavigationController/UITabBarController.

There isn't really any good way to do this. The various subviews of UINavigationController and UITabBarController are both private, and trying to mess with them is likely to not work correctly. And Apple doesn't give us the tools to create "container" view controllers, so you can't easily embed the UINavigationController/UITabBarController inside another view controller or recreate UINavigationController/UITabBarController yourself.

最好的办法可能是继续尝试创建自己的容器"视图控制器,并处理一些无法正常工作的事情.特别是,包含的视图控制器的 parentViewController 将返回 nil,因此包含的视图控制器或其子控制器上的各种其他东西将被破坏(例如 interfaceOrientation 属性将错误,presentModalViewController:animated: 可能无法正常工作).其他东西也可能坏了.

Your best bet is probably to go ahead and try to create your own "container" view controller, and deal with some things not working right. In particular, the contained view controller's parentViewController will return nil, and therefore various other things on the contained view controller or its sub-controllers will be broken (e.g. the interfaceOrientation property will be wrong, presentModalViewController:animated: might not work right). Other things may be broken too.

或者你可以等到未来的某个 iOS 版本真正支持我们创建容器视图控制器(如果有的话),然后只支持那个版本及更高版本.

Or you could wait until some future version of iOS actually has support for us to create container view controllers (if ever), and then support only that version and up.

这篇关于在标签栏控制器/导航控制器上方添加自定义视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆