【发布时间】:2017-07-11 09:06:12
【问题描述】:
我正在尝试在扫描二维码时显示模式弹出窗口。
我有一个 .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];
}];
任何关于我做错的提示将不胜感激!
【问题讨论】:
标签: ios objective-c uiviewcontroller uinavigationcontroller ios9