我正在尝试在扫描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];
}];
任何关于我做错事情的提示将不胜感激!
最佳答案
我发现为什么,我是如此愚蠢!navigationController.modalTransitionStyle = UIModalPresentationFormSheet;
应该navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
关于ios - UINavigationController始终全屏不调整大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45030046/