我正在使用RedLaser SDK。我的应用程序是拆分视图。我正在尝试在主视图控制器上按下按钮时启动RedLaser覆盖。
按下按钮时会调用该方法,这就是问题开始的地方。我有3个不同版本的代码启动叠加层。每个人都有自己的问题。
选项1 这是我的基线,我知道它不起作用,因为我没有初始化叠加层。以下代码正确启动了视图控制器,但(显然)没有按照我想要的方式启动。
// Working Code that brings up dialog but doesn't start camera overlay
SRSScanVINViewController *scanVINViewController y= [[SRSScanVINViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:navController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
选项2 此代码启动覆盖控制器并启动它而不会崩溃。叠加层正在工作,相机处于活动状态。问题是viewcontroller / overlay正在占据整个屏幕。我的控件(按钮等)全部布局,好像视图控制器正在占据屏幕左上角的一部分。如果我可以正确调整叠加大小,这将有效。
// Working code that shows the overlay (camera on) but the overlay takes the whole screen
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
选项3 这种尝试是为了解决选项2(上面)中的问题。这是代码:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pickerController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
崩溃时出现以下错误(nslog):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <SRSMasterViewController: 0x1f59f540>.'
*** First throw call stack:
(0x37ecb88f 0x331fc259 0x30d86441 0x7f6b5 0x7edf7 0x37e253fd 0x30cbfe07 0x30d855e7 0x37e253fd 0x30cbfe07 0x30cbfdc3 0x30cbfda1 0x30cbfb11 0x30cc0449 0x30cbe92b 0x30cbe319 0x30ca4695 0x30ca3f3b 0x3630522b 0x37e9f523 0x37e9f4c5 0x37e9e313 0x37e214a5 0x37e2136d 0x36304439 0x30cd2cd5 0x7deb5 0x7de50)
terminate called throwing an exception
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
我让代码工作但仍有一些问题。这是代码:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
pickerControllerPopover = [[UIPopoverController alloc] initWithContentViewController:pickerController];
[pickerControllerPopover setDelegate:self];
[pickerControllerPopover setPopoverContentSize:CGSizeMake(320.0f, 460.0f)];
[pickerControllerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
else
{
[self presentViewController:pickerController animated:YES completion:nil];
}
这将弹出框的大小设置为与原始控制器相同的大小(在nib中定义)。我仍然有几个问题。
控制器底部的按钮栏中有4个按钮。它还有一个UIImage。第一次加载此控制器时,按钮(和按钮栏和UIImage)要么丢失,要么位于陌生的地方。如果我通过触摸控制器外部的某个屏幕并再次加载控制器来关闭弹出控制器,则控件都在正确的位置。事实上,每次超过第一次,它们都在正确的位置。
有什么想法吗?