Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cameraOverlayView problem on iOS 4.3

I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay. It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.

pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView =  [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];

// Resize
if(imgView.frame.size.height == 480)
{
    //Portrait
    imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
    // Landscape
    imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}

imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;  

pickerController.cameraOverlayView = (UIView *) imgView;

I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480. I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.

Thanks for your help.

like image 402
Geoffrey Avatar asked May 10 '11 15:05

Geoffrey


1 Answers

In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.

You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.

UIView *fullscreenView = [[UIView alloc] initWithFrame:CGRectZero];
fullscreenView.backgroundColor = [UIColor clearColor];
....
 [fullscreenView addSubview:imgView];
pickerController.cameraOverlayView = fullscreenView;
like image 74
Fabian Kreiser Avatar answered Oct 16 '22 00:10

Fabian Kreiser