Pregunta

He estado buscando una respuesta a esto, pero no puedo llegar a nada. Al parecer, el iPhone SDK 3.0 hizo posible que UIImagePickerController se puede mostrar en modo horizontal - pero no estoy encontrando cualquier método que permita esto. Me gustaría pensar que si la aplicación es en el paisaje por defecto sería ajustar automáticamente el controlador de imagen, pero que no funciona para mí.

Gracias por cualquier ayuda!

¿Fue útil?

Solución

No he comprobado si esto es ilegal, pero funcionó para mí. Si desea que el UIImagePickerController para empezar (y mantenerse) en el código de orientación horizontal:

//Initialize picker

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
   picker.delegate = self;


//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

//Refer to the method didRotate:   
[[NSNotificationCenter defaultCenter] addObserver:self
              selector:@selector(didRotate:)
               name:@"UIDeviceOrientationDidChangeNotification" object:nil];

//Set the picker source as the camera   
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Bring in the picker view   
[self presentModalViewController:picker animated:YES];

El didRotate método:

- (void) didRotate:(NSNotification *)notification

{
      //Maintain the camera in Landscape orientation
 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

}

Otros consejos

No hay necesidad de subclase; simplemente reemplazar la propiedad modalPresentationStyle.

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];

Si sólo tiene que deshacerse del intento advertencia

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end

He desarrollado una clase UIImagePicker en modo horizontal. Funciona muy bien para las aplicaciones que he desarrollado: espero que funcione para usted también:

GitHub: https://github.com/imaginaryunit/iOSLandscapeThreadedImagePicker.git

Tengo una aplicación todo-paisaje usando UIImagePickerController también. Obsérvese por favor que si usted llama UIImagePickerController en el modo de paisaje, su aplicación es posible ser rechazado por equipo de revisión de Apple.

ideé un trabajo sencillo evitar este problema, que hacen uso del delegado shouldAutoRotate. Manzana aprueba este método para una aplicación todo-paisaje.

aquí para los detalles y código fuente completo del proyecto descargable.

Hacer una categoría de UINavigationController y añade este método

- (BOOL)shouldAutorotate
{
    return NO;
}

UIImagePickerController Subclase y modalPresentationStyle override como sigue:

- (UIModalPresentationStyle)modalPresentationStyle
{
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        return UIModalPresentationFormSheet;
    }

    return [super modalPresentationStyle];
}

La imagen-selector es un tipo ficha de ahora y ya no en modo de pantalla completa, pero se ve bien en el paisaje-mode. Esto debe ser totalmente app-store-seguro.

Esto funciona para la galería, no para la toma de fotografías.

He resuelto este problema de la siguiente manera: después de cada cambio de orientación, lo sencillo recrear selector. Prueba esto. Lo contrario está demasiado torcido ...

Estoy desarrollando una clase que hace su mayor esfuerzo para trabajar en modo horizontal. Compruébelo usted mismo en GitHub: RACameraController

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top