UINavigationController 总是全屏不调整大小
Posted
技术标签:
【中文标题】UINavigationController 总是全屏不调整大小【英文标题】:UINavigationController always full screen not resizing 【发布时间】: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];
];
任何关于我做错的提示将不胜感激!
【问题讨论】:
【参考方案1】:我知道为什么了,我太笨了!
navigationController.modalTransitionStyle = UIModalPresentationFormSheet;
应该是
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
【讨论】:
以上是关于UINavigationController 总是全屏不调整大小的主要内容,如果未能解决你的问题,请参考以下文章
UINavigationController 在推送控制器时停止动画?
UIScrollerView遇到UINavigationController
UINavigationController 在转换到另一个 VC 时删除阴影
使用 swift 更改 UINavigationController 标题时延迟