如何在复杂的视图层次结构中呈现相机

时间:2018-02-27 10:15:11

标签: ios objective-c

iOS 10.3.1

我有以下视图控制器层次结构......

<TabBarController 0x1463d550>, state: disappeared, view: <UIView 0x146434b0> not in the window
   | <TabMapController 0x146396f0>, state: disappeared, view: <UIView 0x16168be0> not in the window
   |    | <ControlBar 0x1619ad60>, state: disappeared, view: <UIToolbar 0x161b6d40> not in the window
   |    | <ArcGisViewController 0x14d7a200>, state: disappeared, view: <UIView 0x162cd2c0> not in the window
   |    | <iRpMainDashboardViewController 0x14dc1a00>, state: disappeared, view: <UIView 0x16553d60> not in the window
   |    |    | <iRpImageFlipperViewController 0x16615910>, state: disappeared, view: <IGGridView 0x14dfec00> not in the window
   |    |    | <iRpImageFlipperViewController 0x165567e0>, state: disappeared, view: <IGGridView 0x14e31e00> not in the window
   + <UINavigationController 0x14a13800>, state: appeared, view: <UILayoutContainerView 0x16282410>, presented with: <_UIFullscreenPresentationController 0x16cad680>
   |    | <TabMobile 0x15a53400>, state: appeared, view: <UIView 0x162844a0>
   |    |    | <TabMobileDetail 0x16ca63c0>, state: appeared, view: <BaseView 0x162f4020>
   |    |    |    | <MobileAccount 0x16ca8440>, state: appeared, view: <UIView 0x16ca9030>
   |    |    |    |    | <ComboBoxController 0x16cd2510>, state: appeared, view: <ComboBoxView 0x16cce9a0>
   |    |    |    |    | <ComboBoxController 0x16cab940>, state: appeared, view: <ComboBoxView 0x16cd15c0>
   |    |    |    | <MobileCharacteristic 0x16cd2840>, state: appeared, view: <UIView 0x16cd2b60>
   |    |    |    |    | <ComboBoxController 0x16fb7630>, state: appeared, view: <ComboBoxView 0x16d05da0>
   |    |    |    |    | <ComboBoxController 0x16fb9300>, state: appeared, view: <ComboBoxView 0x16d05fc0>
   |    |    |    |    | <ComboBoxController 0x16fb77f0>, state: appeared, view: <ComboBoxView 0x16d060d0>
   |    |    |    |    | <ComboBoxController 0x16fb79b0>, state: appeared, view: <ComboBoxView 0x16d05eb0>
   |    |    |    | <MobileLocation 0x16fb7b70>, state: appeared, view: <UIView 0x16d1ca60>
   |    |    |    |    | <ComboBoxController 0x16d065c0>, state: appeared, view: <ComboBoxView 0x16d21530>
   |    |    |    |    | <ComboBoxController 0x16d2a2f0>, state: appeared, view: <ComboBoxView 0x16d21790>
   |    |    |    | <AxGridPictController 0x16d25b00>, state: appeared, view: <UIView 0x165b2730>
   |    |    | <GridControlBar 0x16aeeff0>, state: appeared, view: <GridControlBarView 0x16d3ddf0>

AxGridPictController(请参阅层次结构底部附近)上面有一个相机按钮。

我在AppDelegate中有代码,当用户点击AxGridPictController上的相机按钮时,它会尝试显示相机。

我在我的AppDelegate中使用此代码呈现相机......

-(void)presentCameraToUser
    {          
        //Create observer for notification
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performTask:) name:@"ImageCapture" object:nil];

        //open camera view controller
        self.cameraViewController = [[AVCamCameraViewController alloc] initWithNibName:@"AVCamCameraViewController" bundle:nil];

        [self.tabBarController presentViewController:self.cameraViewController animated:YES completion:nil];
    }

我没有从AppDelegate引用我的UINavigationController,因为UINavigationController完全来自另一个类。我的相机代码集中到AppDelegate类,这样我的任何一个类都可以使用相机。

您注意到我的演示代码为[self.tabBarController presentViewController... ],但您还会根据视图控制器层次结构注意到,一旦我出示导航控制器,tabBarController就会{ {1}}和state: disappeared因此,我认为尝试使用view: not in the window来展示相机是没用的。

假设我甚至可以获得对UINavigationController的引用,我甚至不确定导航控制器是否能够呈现全屏摄像机视图。

我正在尝试做什么...在导航控制器处于活动状态时展示相机......甚至可能吗?

1 个答案:

答案 0 :(得分:0)

解决方案结果非常简单。而不是使用父视图控制器来 呈现 UINavigationController,而是将 添加 添加到父视图中,就像这样...

-(void)addAChildViewController:(UIViewController *)childViewController
    {
        [self addChildViewController:childViewController];
        [self.view addSubview:childViewController.view];
        [childViewController didMoveToParentViewController:self];
    }

而不是 解雇 UINavigationController,我只是 删除 ,而代码就是这样...... < / p>

-(void)removeThisViewControllerFromItsParent
    {
        [self willMoveToParentViewController:nil];
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
    }