i'm looking at some augmented reality examples using the ARKIT. I'm trying to add a button on top of the camera view to dismiss it, so it goes to its previous screen. When i try to dismiss the view, the camera shuts off and freezes/stops at the camera shutter close animation. (at this point i can still see the button, if i press it again it crashes the app).
The current setup looks like this : Main Menu View -> ARViewController -> Augmented Reality Controller. Maybe someone could tell me where i'm going wrong? or how if theres an easier way to forcefully close all views and display the main menu.
Here is some code :
Main Menu
if([ARKit deviceSupportsAR])
{
ARViewController *viewController = [[ARViewController alloc] initWithDataSource:self];
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHori开发者_如何转开发zontal;
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
ARViewController
.h
AugmentedRealityController *agController;
.m
- (void)loadView {
self.agController = [[AugmentedRealityController alloc] initWithViewController:self];}
- (void)viewDidAppear:(BOOL)animated
{
[agController displayAR];
}
- (void) scanButtonPressed { //action when button is pressed
[agController hideAR]; //dismiss camera
[self dismissModalViewControllerAnimated:YES]; //dismiss current view
}
Augmented Reality Controller
- (void) hideAR {
[[self locationManager] stopUpdatingHeading];
[[self locationManager] stopUpdatingLocation];
[[self accelerometerManager] release];
[rootViewController dismissModalViewControllerAnimated:YES];
}
// This is needed to start showing the Camera of the Augemented Reality Toolkit.
-(void) displayAR {
[rootViewController presentModalViewController:[self cameraController] animated:NO];
[displayView setFrame:[[[self cameraController] view] bounds]];
}
(original source code of the project https://github.com/kypselia/ARKit/blob/d4c018ce74e7c1abd786b6faa71d76435e52246f/ARKit/ARViewController.m)
Not sure if it can solve your problem but you should try using dismissModalViewControllerAnimated only once and tht too using
[self dismissModalViewControllerAnimated:YES];
Hope this will help...
精彩评论