简体   繁体   English

使用UINavigationController的iOS滑出菜单

[英]iOS Slide out menu with UINavigationController

I'm trying to write a slide out menu that uses a main viewcontroller(VC) and three subviews. 我正在尝试编写一个使用主viewcontroller(VC)和三个子视图的滑出菜单。 I want the subviews to be able to be UINavigationControllers if I want...but I'm having trouble adding them as children of the main VC. 我希望子视图能够成为UINavigationControllers ...但是我在将它们添加为主VC的子代时遇到了麻烦。

The main view is the delegate of the center view. 主视图是中心视图的委托。

What seems to be happening is that the nav bar is being given to the main vc and not retained by the child (if that makes any sense). 似乎正在发生的事是导航栏被提供给主vc,而不是被子进程保留(如果这样的话)。 See Image: 见图片:

在此处输入图片说明

I've recently downloaded another library that yields the desired effect (CHSliderMenu) and it works just fine in iOS6/7, but I'm unable to distinguish the difference between what the author is doing and what I'm doing. 我最近下载了另一个可以产生预期效果的库(CHSliderMenu),它在iOS6 / 7中正常工作,但是我无法区分作者在做什么与我在做什么。 I know I'm close, which is what's making this so hard to figure out :( 我知道我已经接近了,这就是为什么很难找出这个原因:(

Here is the code in my MainViewController that attempts to add the child nav controller: 这是我的MainViewController中的尝试添加子导航控制器的代码:

self.view.frame = self.view.bounds;

_centerViewController = [[D2CenterViewController alloc] init];
_centerViewController.view.backgroundColor = [UIColor whiteColor];
_centerViewController.view.tag = CENTER_TAG;
_centerViewController.delegate = self;

UINavigationController *centerNavController = [[UINavigationController alloc] initWithRootViewController:_centerViewController];

[self addChildViewController:centerNavController];
[self.view addSubview:centerNavController.view];

Can you see where I may have gone wrong? 你看得出我可能出了问题吗? Is more code needed to diagnose? 诊断需要更多代码吗?

I implemented one which is built on top of a UINavigationController. 我实现了一个基于UINavigationController的对象。 In order to display the menu behind the navigationController you need to add the menu to the main window of the application instead of adding it as a subview of the navigation controller. 为了在navigationController后面显示菜单,您需要将菜单添加到应用程序的主窗口中,而不是将其添加为导航控制器的子视图。

It also seems like you are moving the viewController inside the navigation controller, instead you need to move that view of the navigation controller, that way all content including the navigation bar can be moved. 好像您正在导航控制器内移动viewController一样,相反,您需要移动导航控制器的该视图,这样可以移动包括导航栏在内的所有内容。

https://github.com/aryaxt/iOS-Slide-Menu https://github.com/aryaxt/iOS-Slide-Menu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM