UINavigationController始终全屏不调整大小

时间:2017-07-11 09:06:13

标签: ios objective-c uiviewcontroller uinavigationcontroller ios9

我正在尝试在扫描QR码时出现模态弹出窗口。

我有一个.xib文件,它具有必要的视图并链接到我的自定义视图控制器。通常的东西,除了我有一个导航控制器,以便我可以在后面添加一个关闭按钮和/或我需要推动另一个屏幕。

为了使事情变得更复杂,我没有直接访问视图控制器(代码在管理器文件中)。这是创建和启动弹出窗口的代码:

self.m_scannerVC = [[BarcodeScannerVC alloc] initWithNibName:NSStringFromClass([BarcodeScannerVC class]) bundle:nil];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.m_scannerVC];

// Set the navigation controller to be a modal popup.
navigationController.modalTransitionStyle = UIModalPresentationFormSheet;

// Set the size of the popup here.
navigationController.preferredContentSize = CGSizeMake(100, 200);

UIWindow *win = [[UIApplication sharedApplication].delegate window];
UINavigationController * winNav = (UINavigationController *)win.rootViewController;
winNav.providesPresentationContextTransitionStyle = YES;
winNav.definesPresentationContext = YES;
winNav.topViewController.providesPresentationContextTransitionStyle = YES;
winNav.topViewController.definesPresentationContext = YES;

winNav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
winNav.topViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

// And now present the view in a modal fashion.
[winNav.topViewController presentViewController:navigationController animated:YES completion:^{
    // Once presented, set the capture layer to fix inside our camera preview box.
    [self.captureLayer setFrame:self.m_scannerVC.m_viewCameraPreview.layer.bounds];
    // Adding the camera AVCaptureVideoPreviewLayer to our view's layer.
    [self.m_scannerVC.m_viewCameraPreview.layer addSublayer:self.captureLayer];

    // Start the camera capture session as soon as the view appears completely.
    [self.captureSession startRunning];

}];  

This is what I am currently seeing - a fullscreen navigation bar with a root view controller

我将非常感谢有关我所做错事的任何提示!

1 个答案:

答案 0 :(得分:1)

我发现了为什么,我真是太蠢了!

navigationController.modalTransitionStyle = UIModalPresentationFormSheet;

应该是

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;