Я разрабатываю приложение для 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. Я также вижу, что метод viewDidAppear
на rootViewController
также вызывается после hideAR. На самом деле, viewDidAppear
звонит displayAR
.
Почему он называется viewDidAppear?
ЧЕТВЕРТОЕ ОБНОВЛЕНИЕ
Я нашел линию, которая терпит неудачу. Это первая строка на displayAR
:
[rootViewController presentModalViewController:[self cameraController] animated:NO];
Есть идеи? rootViewController
и cameraController
не равны нулю.
ОБНОВЛЕНИЕ ФИТ
Если вы хотите воспроизвести мою ошибку:
Я использую iPhone-AR-Toolkit от nielswh (его можно загрузить здесь ).
Вы можете изменить пример ARKitDemo, включить его в библиотеку и попробовать dismissModalView.