拡張現実機能をアプリに統合する必要があります。それを脇に置いてテストした後、今それを統合する準備が整いました。アプリは常に縦向きで実行されるので、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!