Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController doesn't fill screen

screenshot

I'm adding a custom overlay to the UIImagePickerController and there is a persistant black bar at the bottom of the view. Here is my code to instantiate the controller.

- (UIImagePickerController *)imagePicker {     if (_imagePicker) {         return _imagePicker;     }      _imagePicker = [[UIImagePickerController alloc] init];     _imagePicker.delegate = self;      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {         _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;          _imagePicker.showsCameraControls = NO;          _imagePicker.wantsFullScreenLayout = YES;         _imagePicker.navigationBarHidden = YES;         _imagePicker.toolbarHidden = YES;      } else {         _imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;     }      return _imagePicker; } 

The returned controller is displayed modally and works just fine (i.e. displays full screen) when I'm not hiding the camera controls.


Thanks to Ole's suggestion I got it working with this code:

// Resize the camera preview         _imagePicker.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.03); 

A 3% increase in height worked just fine. When I add my custom toolbar at the bottom of the screen there is no longer a visible black bar across the window.

like image 806
kubi Avatar asked Apr 20 '10 10:04

kubi


1 Answers

Scaling by a fixed value isn't a good idea... as I'm sure anyone who used the accepted answer here probably found out when the iPhone 5 came out.

Here's a code snippet to scale dynamically based on the screen resolution to eliminate the letter boxing.

// Device's screen size (ignoring rotation intentionally): CGSize screenSize = [[UIScreen mainScreen] bounds].size;  // iOS is going to calculate a size which constrains the 4:3 aspect ratio // to the screen size. We're basically mimicking that here to determine // what size the system will likely display the image at on screen. // NOTE: screenSize.width may seem odd in this calculation - but, remember, // the devices only take 4:3 images when they are oriented *sideways*. float cameraAspectRatio = 4.0 / 3.0; float imageWidth = floorf(screenSize.width * cameraAspectRatio); float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;  self.ipc.cameraViewTransform = CGAffineTransformMakeScale(scale, scale); 
like image 124
Steve Avatar answered Sep 18 '22 21:09

Steve