Борьба с init Camera - PullRequest
       12

Борьба с init Camera

0 голосов
/ 07 января 2012

работает над приложением камеры, и у меня есть простая, но неприятная проблема.

[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 Ответ

0 голосов
/ 07 января 2012

Похоже, вы просто пытаетесь получить доступ к камере iPhone, чтобы сделать снимок. В этом случае Эта ссылка должна помочь.

...