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];
Jeremie Weldin
  • 184
  • 1
  • 10

3 Answers3

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.

KatokichiSoft
  • 932
  • 5
  • 8
  • This still allows resize and move? – Jeremie Weldin Jan 12 '10 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. – KatokichiSoft Jan 13 '10 at 09: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. – Jeremie Weldin Apr 05 '10 at 17:18
  • I would say no. It didn't work on all version and the selected answer actually did what I needed. – Jeremie Weldin Apr 21 '12 at 08:32
  • @Katokichi: How to get overlay frame size whenever move new frame? – Ram Apr 02 '13 at 05:25
3

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

Jeremie Weldin
  • 184
  • 1
  • 10
  • then why need overlay? i tried doing what suggested above, the overlay won't show up afterwards. – tom Apr 19 '12 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. – Jeremie Weldin Apr 21 '12 at 08: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.