我正在开发一个 iPhone 应用程序,它使用以下代码显示相机的视图:
-(void) displayAR {
[rootViewController presentModalViewController:[self cameraController] animated:NO];
[displayView setFrame:[[[self cameraController] view] bounds]];
}
并使用以下代码隐藏相机的视图:
- (void) hideAR {
[[self locationManager] stopUpdatingHeading];
[[self locationManager] stopUpdatingLocation];
[[self accelerometerManager] release];
[rootViewController dismissModalViewControllerAnimated:YES];
}
当我调用 hideAR 时,我得到一个 EXC_BAD_ACCESS 并带有以下调试器屏幕截图:
替代文字 http://img408.imageshack.us/img408/4550/capturadepantalla201006u.png
有什么建议吗?
更新:
我已经用这个改变了 hideAR 代码,我得到了同样的错误:
- (void) hideAR {
[rootViewController dismissModalViewControllerAnimated:YES];
}
我检查了 rootViewController ,它不是零。
正如您在调试器的屏幕截图中所见,最后调用的方法(堆栈中的第一个方法)是:[UIWindowController transitionViewDidComplete:fromView:toView]
.
也许,在相机被关闭后,有些东西正在访问相机的视图。
第二次更新
包含这些方法的类是:
@implementation AugmentedRealityController
@synthesize locationManager;
@synthesize accelerometerManager;
@synthesize displayView;
@synthesize centerCoordinate;
@synthesize scaleViewsBasedOnDistance;
@synthesize rotateViewsBasedOnPerspective;
@synthesize maximumScaleDistance;
@synthesize minimumScaleFactor;
@synthesize maximumRotationAngle;
@synthesize centerLocation;
@synthesize coordinates = coordinates;
@synthesize debugMode;
@synthesize currentOrientation;
@synthesize degreeRange;
@synthesize rootViewController;
@synthesize cameraController;
- (id)initWithViewController:(UIViewController *)vc {
coordinates = [[NSMutableArray alloc] init];
coordinateViews = [[NSMutableArray alloc] init];
latestHeading = -1.0f;
debugView = nil;
[self setRootViewController: vc];
[self setDebugMode:NO];
[self setMaximumScaleDistance: 0.0];
[self setMinimumScaleFactor: 1.0];
[self setScaleViewsBasedOnDistance: NO];
[self setRotateViewsBasedOnPerspective: NO];
[self setMaximumRotationAngle: M_PI / 6.0];
CGRect screenRect = [[UIScreen mainScreen] bounds];
[self setDisplayView: [[UIView alloc] initWithFrame: screenRect]];
[self setCurrentOrientation:UIDeviceOrientationPortrait];
[self setDegreeRange:[[self displayView] bounds].size.width / 12];
[vc setView:displayView];
[self setCameraController: [[[UIImagePickerController alloc] init] autorelease]];
[[self cameraController] setSourceType: UIImagePickerControllerSourceTypeCamera];
[[self cameraController] setCameraViewTransform: CGAffineTransformScale([[self cameraController] cameraViewTransform], 1.13f, 1.13f)];
[[self cameraController] setShowsCameraControls:NO];
[[self cameraController] setNavigationBarHidden:YES];
[[self cameraController] setCameraOverlayView:displayView];
CLLocation *newCenter = [[CLLocation alloc] initWithLatitude:37.41711 longitude:-122.02528];
[self setCenterLocation: newCenter];
[newCenter release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name: UIDeviceOrientationDidChangeNotification
object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
// Inicializa el gestor del GPS y el del acelerómetro.
[self startListening];
return self;
}
第三次更新
我放了一些 NSLog 跟踪,我看到 displayAR 在 hideAR 调用之后被调用。我还看到在 hideAR 之后也调用了该viewDidAppear
方法。rootViewController
实际上,viewDidAppear
正在调用displayAR
.
为什么叫viewDidAppear?
第四次更新
我找到了失败的线路。这是第一行displayAR
:
[rootViewController presentModalViewController:[self cameraController] animated:NO];
有任何想法吗? rootViewController
并且cameraController
不是零。
第五次更新
如果你想重现我的错误:
我正在使用 nielswh 的 iPhone-AR-Toolkit(你可以在这里下载)。
您可以修改 ARKitDemo 示例,将其包含在库中并尝试关闭 ModalView。