在相机应用程序上工作,我有一个简单但令人沮丧的问题。
[self initCamera];
我需要的是用户完成相机后停止相机的代码。
我已经尝试了[release camera];
等。
任何帮助都会很棒!
以下是可能有帮助的实际代码......
- (void) viewDidAppear:(BOOL)animated {
[self initCamera];
[self startCamera];
self.overlayLabel.text = @"Tap to take pic!";
UIButton *binocsButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
binocsButton.tag = BINOCS_BUTTON_TAG;
[binocsButton setTitle:@"Toggle Binocs" forState:UIControlStateNormal];
binocsButton.backgroundColor = [UIColor clearColor];
binocsButton.frame = CGRectMake(10, 426, 100, 44);
[binocsButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.overlayView addSubview:binocsButton];
UIButton *binocsButton2 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
binocsButton2.tag = BINOCS_BUTTON2_TAG;
[binocsButton2 setTitle:@"Back" forState:UIControlStateNormal];
binocsButton2.backgroundColor = [UIColor clearColor];
binocsButton2.frame = CGRectMake(210, 426, 100, 44);
[binocsButton2 addTarget:self action:@selector(button2Tapped:) forControlEvents:UIControlEventTouchUpInside];
[self.overlayView addSubview:binocsButton2];
}
- (void) initCamera {
if ([BTLFullScreenCameraController isAvailable]) {
NSLog(@"Initializing camera.");
BTLFullScreenCameraController *tmpCamera = [[BTLFullScreenCameraController alloc] init];
[tmpCamera.view setBackgroundColor:[UIColor blueColor]];
[tmpCamera setCameraOverlayView:self.overlayView];
tmpCamera.overlayController = self;
#ifdef BTL_INCLUDE_IMAGE_SHARING
BTLImageShareController *shareController = [[BTLImageShareController alloc] init];
shareController.delegate = self;
[self.view addSubview:shareController.view];
tmpCamera.shareController = shareController;
#endif
self.camera = tmpCamera;
[tmpCamera release];
} else {
NSLog(@"Camera not available.");
}
}
- (void)startCamera {
[self.camera displayModalWithController:self animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
switch (interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[self toggleAugmentedReality];
break;
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
这是我试图关闭它的代码,基本上当你点击binocsbutton2时我希望它关闭视图并返回主菜单:
- (void)button2Tapped:(id)sender {
// [camera release];
// [BTLFullScreenCameraController release];
// [self.camera dismissModalViewControllerAnimated:NO];
// self.camera = nil;
[self dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];
}
带有//的线条是我试图关闭相机操作的线条。但是调试器只是显示它再次初始化!