简体   繁体   中英

take picture method on cameraOverlayView

My problem; Hide the default camera controls and overlay it with my my own. This is made with the property cameraOverlayView. I also was having problem triggering the takePicture method.

(Question solved in the comments and in the edits. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

Here is what came to be the solution:

I have two UIViewController. The main ViewController and the CustomOverlay (for the camera controls).

I the ViewController I declare the source type and the overlay for may camera control like this:

- (void)viewDidLoad
{
    // notification from the CustomOverlay Controller that triggers the eTakePicture method
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eTakePicture:) name:@"eTakePicture" object:nil];

    daysBtn.delegate = self;
    daysBtn.hidden = YES;

    picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;
    picker.wantsFullScreenLayout = YES;
    picker.delegate = self;

    overlay = [[CustomOverlay alloc] initWithNibName:@"CustomOverlay" bundle:nil];
    // Overlay for the camera controls, note the "= overlay.view", the ".view" was important
    // because the overlay is a new UIViewcontroller (with xib) so you have to call the
    // view. Most tutorials that I saw were based on UIView so only "= overlay" worked.
    picker.cameraOverlayView = overlay.view;
    [self presentModalViewController:picker animated:NO];

    [super viewDidLoad];
}

Now on the CustomOverlay, which is a UIViewController I have the take picture button and want this button to trigger a method in the main ViewController:

- (IBAction)shoot:(id)control {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"eTakePicture" object:self];

}

And back to the main ViewController:

-(void)eTakePicture:(NSNotification *)notification
{
    [picker takePicture];
}

All the code above will change a little more once I review it, specially the first block where I have to have a condition to check if cameraSourceType is available.

Hope that helps somebody out there. Any question, just ask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM