with uiimagepickercontrollerdelegate how and iphone uiimagepickercontroller

iphone - uiimagepickercontrollerdelegate - UIImagePickerController no llena la pantalla



uiimagepickercontrollerdelegate swift 4 (11)

captura de pantalla http://i39.tinypic.com/oiermb.png

Estoy agregando una superposición personalizada al UIImagePickerController y hay una barra negra persistente en la parte inferior de la vista. Aquí está mi código para crear una instancia del controlador.

- (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; }

El controlador devuelto se muestra de manera modal y funciona perfectamente (es decir, muestra la pantalla completa) cuando no oculto los controles de la cámara.

Gracias a la sugerencia de Ole, lo conseguí trabajando con este código:

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

Un 3% de aumento en la altura funcionó bien. Cuando agrego mi barra de herramientas personalizada en la parte inferior de la pantalla, ya no hay una barra negra visible en la ventana.


Desde mi experiencia en iOS 7, iphone 5S, para ver el centro de la imagen en la vista previa a pantalla completa, debes concatenar las transformaciones, no hacerlas secuencialmente:

pickerController.cameraOverlayView = self.view; CGSize screenSize = [[UIScreen mainScreen] bounds].size; // 320 x 568 float scale = screenSize.height / screenSize.width*3/4; // screen height divided by the pickerController height ... or: 568 / ( 320*4/3 ) CGAffineTransform translate=CGAffineTransformMakeTranslation(0,(screenSize.height - screenSize.width*4/3)*0.5); CGAffineTransform fullScreen=CGAffineTransformMakeScale(scale, scale); pickerController.cameraViewTransform =CGAffineTransformConcat(fullScreen, translate);


Escalar por un valor fijo no es una buena idea ... ya que estoy seguro de que cualquiera que haya usado la respuesta aceptada aquí probablemente se enteró cuando salió el iPhone 5.

Aquí hay un fragmento de código para escalar de forma dinámica en función de la resolución de la pantalla para eliminar el 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);


Esto funcionó para mí en iOS 10:

let screenSize = UIScreen.main.bounds.size let cameraAspectRatio = CGFloat(4.0 / 3.0) let cameraImageHeight = screenSize.width * cameraAspectRatio let scale = screenSize.height / cameraImageHeight imagePickerController.cameraViewTransform = CGAffineTransform(translationX: 0, y: (screenSize.height - cameraImageHeight)/2) imagePickerController.cameraViewTransform = imagePickerController.cameraViewTransform.scaledBy(x: scale, y: scale)


Hola, vi que algunas personas seguían recibiendo la barra negra en la parte inferior después de calcular la escala para el iPhone 5. Tuve este problema por un tiempo, pero luego descubrí que debes traducir la vista para que esté en el medio de la pantalla y luego aplica la escala ¡Aquí está mi código para hacer esas dos cosas y me funciona!

CGSize screenBounds = [UIScreen mainScreen].bounds.size; CGFloat cameraAspectRatio = 4.0f/3.0f; CGFloat camViewHeight = screenBounds.width * cameraAspectRatio; CGFloat scale = screenBounds.height / camViewHeight; m_imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0); m_imagePickerController.cameraViewTransform = CGAffineTransformScale(m_imagePickerController.cameraViewTransform, scale, scale);


La relación de aspecto de la cámara es 4: 3 y la relación de aspecto de la pantalla es 3: 2. Entonces, simplemente no hay forma de que la imagen de la cámara llene la pantalla a menos que esté dispuesto a recortar a 3: 2. Para hacer eso, aplique una transformación de escala apropiada.


Pruebe usar este código:

picker.wantsFullScreenLayout = YES; CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.47); picker.view.transform = scale;


Transfórmalo con esto:

#define CAMERA_TRANSFORM 1.12412 _picker.wantsFullScreenLayout = YES; _picker.cameraViewTransform = CGAffineTransformScale(_picker.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);


Usé este método para calcular la escala.

// get the screen size CGSize screenSize = [[UIScreen mainScreen] bounds].size; // establish the height to width ratio of the camera float heightRatio = 4.0f / 3.0f; // calculate the height of the camera based on the screen width float cameraHeight = screenSize.width * heightRatio; // calculate the ratio that the camera height needs to be scaled by float scale = screenSize.height / cameraHeight; imagePicker.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);


Y aquí la respuesta en Swift.

let screenSize:CGSize = UIScreen.mainScreen().bounds.size let ratio:CGFloat = 4.0 / 3.0 let cameraHeight:CGFloat = screenSize.width * ratio let scale:CGFloat = screenSize.height / cameraHeight let imag:UIImagePickerController = UIImagePickerController() imag.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0) imag.cameraViewTransform = CGAffineTransformScale(imag.cameraViewTransform, scale, scale)


mi problema resuelto :)

//Camera is 426 * 320. Screen height is 568. Multiply by 1.333 in 5 inch (iPhone5) to fill vertical CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points self.imagePickerController.cameraViewTransform = translate; CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333); self.imagePickerController.cameraViewTransform = scale;


PickerViewController.m #define CAMERA_TRANSFORM 1.8 - (void)viewDidAppear:(BOOL)animated { if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { // type = UIImagePickerControllerSourceTypeCamera; UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.allowsEditing = NO; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.showsCameraControls=NO; picker.extendedLayoutIncludesOpaqueBars = YES; picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM , CAMERA_TRANSFORM); [self presentViewController:picker animated:YES completion:nil]; }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Device have no camera" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } }