2012-10-24 72 views
0

这是事情,我必须将增强现实功能集成到应用程序中。经过测试,现在我已经准备好整合它了。该应用程序始终以纵向模式运行,我决定以横向或左侧旋转iPhone时显示增强现实(当然,如果我以纵向显示原始视图控制器,则返回)。事实上,增强现实是以模态方式呈现的。模态视图控制器在呈现2/3次后不再呈现

我有viewController调用ARViewController(模态)。它可以正常工作,如果我旋转2或3次,但这个ARViewController不再被调用,但应用程序仍在运行,没有崩溃,没有冻结。此ARViewController使用ARController进行初始化,ARController是增强现实所需的一类计算。如果我在没有ARController的情况下调用这个ARViewcontroller,那么在视图控制器之间切换工作得很好,将会调用一个空白窗口,但至少我可以根据需要旋转设备。所以,这必须来自ARController,我记录了自己的内存泄漏(按照我使用ARC的方式),我认为这可能是导致问题的原因,因为我多次使用此ARController。

但在进一步,我想知道如果我做错什么,可以通过视图控制器之间的切换影响ARController:

这里是我所说的ARViewController中的viewController:

if (orientation == UIDeviceOrientationLandscapeLeft) { 
     NSLog(@"ViewController Landscape left"); 
     ARViewController *arVC = [[ARViewController alloc] initWithNibName:@"ARViewController" bundle:nil]; 
     [self setCameraViewController:arVC]; 
     [arVC setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal]; 
     [[self navigationController] presentModalViewController:cameraViewController animated:YES]; 
     arVC = nil; 
    } 
    else if (orientation == UIDeviceOrientationLandscapeRight) { 
     NSLog(@"ViewController Landscape Right"); 
     ARViewController *arVC = [[ARViewController alloc] initWithNibName:@"ARViewController" bundle:nil]; 
     [self setCameraViewController:arVC]; 
     [arVC setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal]; 
     [[self navigationController] presentModalViewController:cameraViewController animated:YES]; 
     arVC = nil; 
    } 

ARViewController的初始化:

- (void)viewDidLoad { 
[super viewDidLoad]; 
self.arController = [[ARController alloc] initWithViewController:self]; 
arController.filterDiscover = filterDiscover; 
arController.filterEat = filterEat; 
arController.filterSleep = filterSleep; 

// Listen for changes in device orientation 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object:nil]; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

//if ViewController presents this modal ARViewController 
if(!arController.filterDiscover && !arController.filterEat && !arController.filterSleep) 
    [arController callAlertViewToFilter]; 
else 
    [arController loadData]; 
} 

最后这里是我回到原来的视图控制器,如果我旋转肖像ARViewController:

if (orientation == UIDeviceOrientationPortrait){ 
    NSLog(@"ARViewController Portrait"); 
    [self setArController:nil]; 
    [[super presentingViewController] dismissModalViewControllerAnimated:YES]; 
} 

我试图尽可能清楚,如果任何人有过类似这样的问题,也可能是巨大的有一些线索来解决这个问题。我可以显示ARController的代码,但它有点太长了,现在我只想知道这里是否有任何问题。如果需要,我会展示它。

这也许会有帮助,我发现在调试区,该输出将不被再显示ARViewController:

2012-10-24 17:57:51.072 beiceland[20348:907] ViewController Landscape Right 
2012-10-24 17:57:51.073 beiceland[20348:907] Warning: Attempt to present <ARViewController: 0x203f0c60> on <RevealController: 0x1cd5dca0> while a presentation is in progress! 

回答

1

我不好,我是这里的解决方案。

我使用的调试和断点和重复序列的关键,我发现我并没有进入:

- (void)deviceOrientationDidChange:(NSNotification *)notification 

了。所以这是我第一次看到这样的事情,设备方向改变的听众突然停止发射。因此我的解决方案是相当残酷的,但至少它停止发行的优点,只是检测设备的方向变化后,我停止监听:

if (orientation == UIDeviceOrientationLandscapeLeft) { 
     NSLog(@"ViewController Landscape left"); 
     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 
     [[NSNotificationCenter defaultCenter] removeObserver:self]; 
     ARViewController *arVC = [[ARViewController alloc] initWithNibName:@"ARViewController" bundle:nil]; 
     [self setCameraViewController:arVC]; 
     arVC = nil; 
     [cameraViewController setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal]; 
     [[super navigationController] presentModalViewController:cameraViewController animated:YES]; 
} 

而且我使用的viewController每次(调用视图控制器),我重新初始化监听器,这意味着在viewDidAppear:

// Listen for changes in device orientation 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object:nil]; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

那么现在它的解决,但我不得不承认,我很失望,找到这样一种解决方案。

0

嗯,我从来没有使用ARC,但据我所看到的,你初始化每次更改方向时(横向)ARViewController。为什么不实例化2 ARViewController并每次都调用它们?

除非您确定每次切换到肖像时都会释放这些内容。

另外,你为什么不只是使用pushViewController:animated:

还有最后一件事,你向你的navigationController提供了ModalViewController,但是你在[super presentsViewController]中解雇了它,也许你可以添加这个呢?

+0

我试过pushViewController,起初它似乎是显示AR的最明显的方式。但由于我的应用程序只有肖像的方向限制(项目设置),当我显示AR时,只有3/4的屏幕区域是活动的touchesBegan,奇怪...使用模态它工作正常。没有它,我会使用pushViewController。对不起,我没有得到你说的那些东西。 –

+0

对不起,我的意思是说,也许你可以发布代码[超级presentsViewController] – Snaker

+0

对不起,但唯一我发现足够接近你的最新警告是[this](http://stackoverflow.com/questions/12596882/modal -uinavigationcontroller-hides-though-not-dismisses) – Snaker

相关问题