是否可以使用UINavigationController以不使用完整窗口的方式?非全屏UINavigationController
我试着设置它的视图的框架以及添加它的视图到另一个(非全屏)视图,而不是窗口,并且都没有工作。
是否可以使用UINavigationController以不使用完整窗口的方式?非全屏UINavigationController
我试着设置它的视图的框架以及添加它的视图到另一个(非全屏)视图,而不是窗口,并且都没有工作。
这可能有帮助吗?
Adding a UINavigationController as a subview of UIView
你总是可以直接使用UINavigationBar的类,并自己实现的控制代码。
这很难回答,因为它很复杂。
在iPhone上,您不能拥有比屏幕短的UINavigationController。 因此,如果您想显示广告条幅,请将其显示在底部工具栏上方或顶部导航栏下方。
在iPad上,您可以并排放置两个UINavigationControllers,但在我的情况下,它们仍然占据整个屏幕的高度。鉴于iPhone的行为,我没有尝试修改iPad上的高度行为。
不能直接更改UINavigationController或其子视图的大小,因为UINavigationController会自动将其大小调整为全屏,而不管它们的框架设置为何。我已经能够克服这个问题的唯一办法,到目前为止如下:
首先,创建的UINavigationController的一个实例,你通常会:
UINavigationController *nc = [[UINavigationController alloc] init];
self.navController = nc;
[nc release];
然后,创建UIView的实例,受限于大小你真的想:
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的视图中,如上所示。
需要注意的是,添加到UINavigationController的任何UIViewController视图都将其内容限制为navView的界限,而不是添加到UINavigationController的子视图的框架,因此应该创建每个子视图中的内容以便正确显示NavView的边界。
无论如何,这项技术确实有效,因为我已经创建了一个成功使用它的应用程序。我得到这个工作的唯一方法是从零开始创建一个自定义的导航控制器类,复制UINavigationController的功能,但没有自动调整大小(我以前也做过),并且这可以是痛苦。希望这可以帮助。
我爱你,谢谢 – 2014-06-03 13:23:10
这是我有史以来的第一篇文章,虽然我一直在从这个社区学到很多。所以我想为此感谢你。
我的挑战和我在这里发布的原因是为了回答这个问题,并根据我的需要重构它,使用iOS5和故事板。这个解决方案可能不适用于较旧的实现,但我想我会发布它。
这就是我最终的结果,它运行良好(iPad应用程序)。这是在我的默认UIViewController上设置的,在故事板视图中设置为root。
希望这可以帮到你!
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*vars:
rightSideView is the containing view - this is where the UINavigationController will sit, along with it's view stack
myStoryboard is self-explanatory I think
myViewController is identified as in storyboard as "accountView", to be pulled from the storyboard and used as the rootview
*/
//Steps
//Add subview to this controller's view (for positioning)
UIView *rightSideView = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 500, 600)];
rightSideView.clipsToBounds = YES;//this little baby makes sure that the damn navigation bar clips!!
rightSideView.backgroundColor = [UIColor grayColor];//so I can see it
//instantiate view controller for nav controller's root view
UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myViewController = [myStoryboard instantiateViewControllerWithIdentifier:@"accountView"];
//create NavController
UINavigationController *myNavController = [[UINavigationController alloc]initWithRootViewController:myViewController];
//Add navController as one of my child ViewControllers
[self addChildViewController:myNavController];
//Add NavController's view into my constrained view
[rightSideView addSubview:myNavController.view];
//Finally, add right side view as a subview of myself
[self.view addSubview:rightSideView];
}
这就是我需要的,谢谢! – 2012-06-02 18:38:25
你是如何解决这个问题的? – Zebs 2011-03-06 07:36:26
@bentford你怎么解决这个问题? – 2011-03-20 19:22:17
你是谁,DenverCode9?你看见什么了?! – buley 2014-07-18 02:01:08