简体   繁体   English

出现2/3次后,不再显示模态视图控制器

[英]Modal view controller not presented anymore after being presented 2/3 times

Here is the thing, I have to integrate an augmented reality functionality into an app. 这就是问题,我必须将增强现实功能集成到应用程序中。 After testing it aside, now I'm ready to integrate it. 经过一番测试之后,现在我可以集成它了。 The app always runs in Portrait, I decided to show the augmented reality when rotating the iPhone in Landscape Right or Left (and of course, if I go back in Portrait the original view controller is shown). 该应用程序始终以纵向运行,我决定向右或向左旋转iPhone时显示增强现实(当然,如果返回纵向,则显示原始视图控制器)。 In fact the augmented reality is presented modally. 实际上,增强现实是以模态呈现的。

I've got viewController calling ARViewController (modally). 我有viewController调用ARViewController(以模式方式)。 It works fine if I rotate like 2 or 3 times, but then this ARViewController is not called anymore, but the app is still running, no crash, no freeze. 如果我旋转2到3次,效果很好,但是不再调用此ARViewController,但是该应用程序仍在运行,没有崩溃,没有冻结。 This ARViewController is initialised with ARController, a class computing all needed for the augmented reality. 该ARViewController由ARController初始化,ARController是一个类,用于计算增强现实所需的全部内容。 If I call this ARViewcontroller without the ARController, switching between the view controllers works very fine, a blank window will be called but at least I can rotate the device as much as I want. 如果我在没有ARController的情况下调用此ARViewcontroller,则在视图控制器之间进行切换的效果非常好,将调用一个空白窗口,但至少我可以根据需要旋转设备。 So, this must come from the ARController, I documented myself on memory leaks (by the way I'm using ARC), I think this could be the reason to the issue since I'm using this ARController many times. 因此,这必须来自ARController,我记录了内存泄漏的情况(通过我使用ARC的方式),我认为这可能是导致此问题的原因,因为我已多次使用此ARController。

But before going further, I'd like to know if I'm doing anything wrong that could influence the ARController by switching between view controllers: 但是在进一步介绍之前,我想知道我是否做错了任何可能会通过在视图控制器之间切换来影响ARController的事情:

Here is how I call the ARViewController in viewController: 这是我在viewController中调用ARViewController的方法:

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;
    }

the initialisation of ARViewController: 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];
}

And finally here is how I go back to the original view controller if I rotate to Portrait in ARViewController: 最后,如果我在ARViewController中旋转到Portrait,这就是我回到原始视图控制器的方式:

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

I tried to be as clear as possible, if anyone has ever had an issue similar to this, it could be great have some clues to solve this. 我试图尽可能地清楚一些,如果有人遇到过类似的问题,那么可能会有一些线索可以解决这个问题。 I could have shown the code of the ARController but it is a little too long, for now I'd just like to know if there is anything wrong here. 我本可以显示ARController的代码,但是它太长了,现在,我只想知道这里是否有错误。 If needed I'll show it. 如果需要,我会显示。

This might help, I found this output in the debug area when the ARViewController is not being displayed anymore: 这可能会有所帮助,当不再显示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!

My bad I was way out of the solution here. 我不好,我无法解决这里的问题。

I used the debugger and breakpoints and repeated the critical sequence, I found out I was not entering: 我使用了调试器和断点,并重复了关键的顺序,发现我没有进入:

- (void)deviceOrientationDidChange:(NSNotification *)notification

anymore. 不再。 So this is the first time I see such things, the listener for device orientation changes suddenly stops firing. 因此,这是我第一次看到这种情况,设备定向更改的侦听器突然停止触发。 Consequently my solution is quite brutal but at least it has the merit of stopping the issue, just after detecting the device orientation change I stop the listener: 因此,我的解决方案非常残酷,但至少它具有停止问题的优点,就在检测到设备方向更改后,我就停止了侦听器:

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];
}

And each time I'm using the viewController (the calling view controller), I reinitialize the listener, it means in viewDidAppear: 每次我使用viewController(调用视图控制器)时,都会重新初始化侦听器,这意味着在viewDidAppear:

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

Well now it's solved but I have to admit I'm disappointed of finding such kind of solution. 好了,现在解决了,但是我不得不承认我对找到这种解决方案感到失望。

Well, I never used ARC before, but according to what I see, you initialize a ARViewController everytime you change orientation ( on landscape ). 好吧,我以前从未使用过ARC,但是根据我所看到的,每次更改方向(在landscape上)时,都要初始化一个ARViewController。 Why not instantiating 2 ARViewController for good, and calling them everytime ? 为什么不实例化2个ARViewController并每次都调用它们呢?

Except if you are sure that these are released everytime you switch to portrait. 除非您确定每次切换为肖像时都会释放它们。

Plus, why don't you just use pushViewController:animated: ? 另外,为什么不只使用pushViewController:animated :

And one last thing, you presentModalViewController to you navigationController, but you dismiss it in [super presentingViewController], maybe you could add this one ? 最后一件事,您向NavigationController展示了ModalViewController,但是您在[super presentingViewController]中将其关闭了,也许您可​​以添加这个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在applicationDidFinishLaunchingWithOptions中未显示模态视图控制器? - Why is the modal view controller not being presented in applicationDidFinishLaunchingWithOptions? 在呈现模态视图控制器之后推动导航控制器 - Pushing a navigation controller after a modal view controller is presented 模态视图控制器内的 UITable 视图 - UITable view inside modal presented view controller 解雇由模态视图控制器呈现的UIAlertController - dismiss UIAlertController presented by a modal view controller 出现模态视图 controller 时暂停 animation - Pause animation when modal view controller is presented 呈现的模态视图控制器未像表单一样显示 - Presented Modal view controller not displayed like a Form 如何知道视图控制器是作为弹出窗口还是模态显示? - How to know if a view controller will be presented as a popover or modal? 呈现后被 UITransitionView 阻止的视图 - View being blocked by UITransitionView after being presented willRotateToInterfaceOrientation未在模态呈现的视图控制器中调用 - willRotateToInterfaceOrientation not being called in a modally presented view controller 确定如何呈现视图控制器 - Determine how a view controller is being presented
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM