2012-01-07 22 views
-3

カメラアプリで作業していて、シンプルで不満な問題があります。initで苦労しているカメラ

[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

+0

リアカメラを起動して撮影します。私が必要とするのは、initCameraの反対です。 – Clive

+1

'initCamera'を見ることはできますか?あなたが私たちに何か情報をまったく提供していないときには、答えが出にくいです。 – Emil

答えて

0

あなたは写真を撮るためにiPhoneカメラにアクセスしようとしているように聞こえます。その場合は、This linkが役立ちます。

+0

私が持っているコードは非常に複雑で、オーバーレイとイメージの保存が必要です。本当に必要なのは実際には「init」の逆です。または、カメラを閉じる方法はたくさんあります。現在、binocsbutton2を押すとカメラは終了し(アニメートされますが)、再起動されるので、ビューは閉じません。私がinitカメララインを取り出すと、すべてが正常に動作するようになります(ただし、カメラは一切ありません)。 – Clive