2012-01-07 87 views
-3

在相機應用程序上工作,我有一個簡單但令人沮喪的問題。用初始相機掙扎

[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]; 
    } 

帶//的行是我試圖關閉相機操作的行。但調試器只是顯示它重新初始化!

+1

什麼是相機? '[self initCamera];'做什麼? – Emil 2012-01-07 17:34:17

+0

它啓動後置攝像頭進行拍照。我需要的只是initCamera的反面 – Clive 2012-01-07 17:45:33

+1

我們可以看到'initCamera'嗎?當你根本沒有提供任何信息時,很難回答。 – Emil 2012-01-07 17:49:56

回答

0

這聽起來像你只是想訪問iPhone相機拍照。在這種情況下,This link應該有所幫助。

+0

我擁有的代碼非常複雜,涉及覆蓋和保存圖像,我真正需要的實際上與「init」相反。或者有很多方法可以關閉相機。目前相機在按下binocsbutton2時會關閉(動畫),但隨後會重新啓動,因此視圖不會關閉。如果我拿出init相機線,整個事情就會像原來那樣工作(但沒有相機!) – Clive 2012-01-07 18:57:52