views:

556

answers:

2

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];
A: 

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
This still allows resize and move?
Jeremie Weldin
KatokichiSoft
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
They did approve it.
Jeremie Weldin
A: 

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

Jeremie Weldin