3

I used to use the old-school method of adding an overlay to the camera screen, and that worked fine. However, since 3.1 came out, Apple is insisting that I use the API to add an overlay. I quickly got the overlay to work, but it seems that if I use the custom overlay, then the move & resize screen is not responsive, I can only use or retake, can't actually resize & move. The code I am using is below. I have tried several variations, but the only thing that actually enables the move & resize is to remove the line that adds the custom overlay view.

Any ideas?

UIImage *image = [UIImage imageNamed:@"camera-template-long.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] ;
imgView.image = image;

UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
[overlayView addSubview:imgView];

UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;        
picker.showsCameraControls = YES;
picker.cameraOverlayView = overlayView;
picker.delegate = self;
picker.allowsEditing = YES;

[self presentModalViewController:picker animated:YES];

3 Answers 3

3

Set both allowsEditing/showsCameraControls properties to NO, prepare your original view to cameraOverlayView, and use takePicture method.

Then, imagePickerController:didFinishPickingMediaWithInfo: will be called directly.


Please try the following code:

- (void)foo {
  UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease]; 
  controller.sourceType = UIImagePickerControllerSourceTypeCamera; 
  controller.cameraOverlayView = self.cameraOverlay; 
  [self performSelector:@selector(moveOverlayViewToSublayer:) withObject:controller afterDelay:0.1f]; 
  controller.delegate = self; 
  [self presentModalViewController:controller animated:YES]; 
}
- (void) moveOverlayViewToSublayer:(UIImagePickerController*)controller { 
  CALayer *aLayer = self.cameraOverlay.layer.superlayer; 
  controller.cameraOverlayView = nil; 
  [aLayer addSublayer:self.cameraOverlay.layer]; 
}

I hope it will work well.

5
  • This still allows resize and move? Jan 12, 2010 at 18:07
  • Sorry, I misunderstood your question. Your question is "How to activate resize&crop operation when a custom overlay is added?", isn't it? I have changed my answer. Jan 13, 2010 at 9:20
  • 1
    This worked, with a subtle change, I needed to keep both allowsEditing and showsCameraControls set to YES. Thanks. Now let's see if Apple will approve it. I get a warning that CALayer addSublayer is not valid. Apr 5, 2010 at 17:18
  • I would say no. It didn't work on all version and the selected answer actually did what I needed. Apr 21, 2012 at 8:32
  • @Katokichi: How to get overlay frame size whenever move new frame?
    – Ram
    Apr 2, 2013 at 5:25
3

The entire issue goes away once you use [overlayView setUserInteractionEnabled:NO]; to stop the overlay view from handling the input.

2
  • then why need overlay? i tried doing what suggested above, the overlay won't show up afterwards.
    – tom
    Apr 19, 2012 at 22:02
  • I only need the overlay to display a frame over the live camera view. I don't need any user interaction in my overlay. Apr 21, 2012 at 8:31
0

http://www.techques.com/question/1-10178214/cameraOverlayView-prevents-editing-with-allowsEditing

This works perfectly for me. I tried to disable userInteractionEnabled but in vain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.