在相機應用程序上工作,我有一個簡單但令人沮喪的問題。用初始相機掙扎
[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];
}
帶//的行是我試圖關閉相機操作的行。但調試器只是顯示它重新初始化!
什麼是相機? '[self initCamera];'做什麼? – Emil 2012-01-07 17:34:17
它啓動後置攝像頭進行拍照。我需要的只是initCamera的反面 – Clive 2012-01-07 17:45:33
我們可以看到'initCamera'嗎?當你根本沒有提供任何信息時,很難回答。 – Emil 2012-01-07 17:49:56