非全屏UINavigationController [英] Non-fullscreen UINavigationController

查看:470
本文介绍了非全屏UINavigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用UINavigationController,以不使用完整的窗口?

Is it possible to use a UINavigationController in such a way that it doesn't use the full window?

我已经尝试设置它的视图的框架以及

I've tried setting it's view's frame as well as adding it's view to another (non-fullscreen) view instead of the window, and neither seems to work.

推荐答案

不能直接使用直接更改UINavigationController或其子视图的大小,因为UINavigationController会自动将其大小调整为全屏,无论它们的框架设置为什么。到目前为止,我已经能够克服这种情况的唯一方法如下:

You cannot directly change the size of a UINavigationController or it's subviews directly, as the UINavigationController automatically resizes them to full screen, no matter what their frames are set to. The only way I've been able to overcome this so far is as follows:

首先,像通常一样创建一个UINavigationController的实例:

First, create an instance of UINavigationController as you normally would:

UINavigationController *nc = [[UINavigationController alloc] init];
self.navController = nc;
[nc release];

然后,创建一个UIView的实例,约束到你真正想要的大小:

Then, create an instance of UIView, constrained to the size you really want:

UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, DESIRED_HEIGHT)];
navView.clipsToBounds = YES;
[navView addSubview:self.navController.view];   
[self.view addSubview:navView];
[navView release];

navView的clipsToBounds属性必须设置为YES,否则UINavigationController和它的视图将仍然显示全屏。然后,将UINavigationController添加到该约束视图。这个UIView可以被添加到UIViewController的视图,如上所示。

The navView's clipsToBounds property must be set to YES, or the UINavigationController and it's view will still appear fullscreen. Then, add the UINavigationController to that constrained view. This UIView may then be added to the UIViewController's view, as seen above.

需要注意的是,添加到UINavigationController的任何UIViewController的视图都将有自己的内容限制到navView的边界,而不是添加到UINavigationController的子视图的框架,因此应该创建每个子视图中的内容以正确显示navView的边界。

The thing to note is that any UIViewController's views that are added to the UINavigationController will all have their content constrained to navView's bounds, not the frame of the subviews added to the UINavigationController, so the content in each subview should be created to properly display for the navView's bounds.

在任何case,这种技术工作,因为我创建了一个成功使用它的应用程序。我唯一的其他方法是从头开始创建一个自定义的导航控制器类,复制UINavigationController的功能,但没有自动调整大小(我在过去也做过),可以是痛苦。希望这有助于。

In any case, this technique does work, as I've created an app that successfully uses it. The only other way I've ever gotten this to work is to create a custom navigation controller class from scratch, replicating the functionality of UINavigationController, but without the automatic resizing (which I've also done in the past), and that can be a pain. Hope this helps.

这篇关于非全屏UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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