0

拡張現実機能をアプリに統合する必要があります。それを脇に置いてテストした後、今それを統合する準備が整いました。アプリは常に縦向きで実行されるので、iPhone を横向きに右または左に回転させたときに拡張現実を表示することにしました (もちろん、縦向きに戻すと元のビュー コントローラーが表示されます)。実際、拡張現実はモーダルに表示されます。

ARViewController (モーダル) を呼び出す viewController があります。2 ~ 3 回回転すると問題なく動作しますが、この ARViewController はもう呼び出されませんが、アプリはまだ実行されており、クラッシュもフリーズもありません。この ARViewController は、拡張現実に必要なすべてを計算するクラスである ARController で初期化されます。ARController なしでこの ARViewcontroller を呼び出すと、View Controller 間の切り替えが非常にうまく機能し、空白のウィンドウが呼び出されますが、少なくともデバイスを好きなだけ回転させることができます。したがって、これは ARController から来ているに違いありません。私はメモリ リークについて自分自身を文書化しました (ARC を使用しています)。この ARController を何度も使用しているため、これが問題の原因である可能性があると思います。

しかし、さらに先に進む前に、View Controller を切り替えることで ARController に影響を与える可能性のある何か間違ったことをしていないかどうかを知りたいです。

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

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!
4

2 に答える 2

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

さて、それは解決されましたが、そのような種類の解決策を見つけることに失望していることを認めなければなりません.

于 2012-10-25T10:09:32.110 に答える
0

ええと、私は以前に ARC を使用したことはありませんが、私が見たところによると、方向を変更するたびに ARViewController を初期化します ( on landscape )。2 つの ARViewController をインスタンス化して、毎回呼び出してみませんか?

ポートレートに切り替えるたびにこれらが解放されることが確実な場合を除きます。

さらに、 pushViewController:animated:を使用しないのはなぜですか?

最後に、ModalViewController を navigationController に提示しますが、[super presentingViewController] でそれを却下します。これを追加できますか?

于 2012-10-24T15:16:53.300 に答える