试试这个方法:
在加载视图中设置一些容器如下:
(此示例在主要内容下创建导航菜单,您可以滑动以显示)。
- (void)loadView
{
CGRect fullScreen = [UIScreen mainScreen].bounds;
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, statusBarFrame.size.height, fullScreen.size.width,
fullScreen.size.height - statusBarFrame.size.height)];
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
_mainNavigationContainer =
[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 60, self.view.frame.size.height)];
[_mainNavigationContainer setHidden:YES];
[self.view addSubview:_mainNavigationContainer];
_mainContentViewContainer = [[GGMainContentContainer alloc] initWithFrame:self.view.bounds];
[_mainContentViewContainer setNavigationDelegate:self];
[self.view addSubview:_mainContentViewContainer];
}
完成后,创建一个方法来接受子控制器
- 您应该在子控制器的视图中找到适当的容器,将视图的框架设置为容器的边界。
- 你应该有你的容器视图控制器,在使用期间保留子控制器。
代码:
- (void)setMainNavigationController:(UIViewController*)mainNavigationController
{
_mainNavigationController = mainNavigationController;
[_mainNavigationController.view setFrame:_mainNavigationContainer.bounds];
[_mainNavigationController willMoveToParentViewController:self];
[_mainNavigationContainer addSubview:_mainNavigationController.view];
[_mainNavigationController didMoveToParentViewController:self];
}
这是在运行时为主容器设置动画的示例
- (void)pushViewController:(UIViewController*)viewController replaceRoot:(BOOL)replaceRoot
{
if ([_controllerStack peek] == nil)
{
[_controllerStack push:viewController];
[_mainContentViewContainer setContent:viewController.view navigationBarOrNil:[self makeNavigationBarForTopController]];
}
else
{
if (replaceRoot)
{
[_controllerStack removeAllObjects];
}
[self slideToViewController:viewController direction:GGSlideAnimationDirectionFromRight];
}
}
这里有一些幻灯片和示例可能会有所帮助:
https://speakerdeck.com/peterfriese/ios-5-uiviewcontroller-containment