2012-01-20 18 views
5

En mi aplicación IOS, cuando abro la cámara coloco una imagen sobre la vista de la cámara. Se ve bien en modo retrato. Pero cuando se cambia al modo horizontal, se ve algo extraño. Por lo tanto, quiero bloquear el UIImagePickerController en modo vertical.bloquear UIImagePickerController en el modo vertical en la aplicación ios

que sigue es mi código para una imagen ui controlador selector de

UIImagePickerController *imgPkr = [[UIImagePickerController alloc] init]; 
imgPkr.delegate = self; 
imgPkr.sourceType = UIImagePickerControllerSourceTypeCamera; 

Cómo se puede bloquear en modo vertical ....

Respuesta

2

Ésta no es la mejor solución, pero funciona:

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; 
[appDelegate.window addSubview:cameraOverlay]; 
imgPicker.cameraOverlayView = appDelegate.window.superview; 

La cámara en el fondo sigue girando, pero su punto de vista superposición Indiferente. Espero que funcione para usted

+0

No funciona en iOS5 – filou

0

Sólo tiene que escribir el código en su controlador de vista

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations. 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
+0

no uso ... sigue siendo el mismo problema ... –

+0

Acepto Return NO. o escriba este código –

+0

[[UIDevice currentDevice] setOrientation: UIDeviceOrientationPortrait]; –

0

Agregue una categoría en UIImagePickerController y anule su método shouldAutoRotateToInterfaceOrientation, de la siguiente manera:

@implementation UIImagePickerController (NoRotate) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 
+0

He creado dos archivos: UIIMagePickerController + NoRotate.hy .m. He agregado esto a .m, he incluido los archivos en viewController que llama al UIImagePickerController pero el selector todavía gira. ¿Necesito subclasificar al selector? Gracias. – SpaceDog

+0

No debería necesitar, permítame probarlo y me pondré en contacto con usted. –

+0

ok gracias !!!!!! – SpaceDog

1

No tiene que "bloquear el controlador UIImagePicker en modo vertical". Como dijiste "cuando se cambia al modo horizontal, se ve algo extraño" En realidad, no sé por qué dices que parece extraño. Pero, aquí está mi experiencia de UIImagePicker ver extraño en modo horizontal. Esto es: Cuando AViewController es el controlador de vista raíz. Y la vista de BViewController agrega subvista a la vista de AViewController. y presentModalViewController:UIImagePickerController en BViewController. La vista de UIImagePicker parecerá impar en modo apaisado.

La solución a este problema se establece en UIImagePickerController como el controlador de vista raíz antes de presentModelViewController. El código fuente a continuación muestran el detalle:

- (void) onCameraButtonTapped:(UIBarButtonItem *)buttonItem 
{ 
    //backupRootController it's use as a backup, it will recover after close the image picker controller. 
    self.backupRootController = [[UIApplication sharedApplication] keyWindow].rootViewController; 

    UIImagePickerController * imageController = [[UIImagePickerController alloc] init]; 
    imageController.sourceType = UIImagePickerControllerSourceTypeCamera; 
    imageController.delegate = self; 
    .... 
    [[[UIApplication sharedApplication] keyWindow] setRootViewController:imageController]; 
    [self presentModalViewController:imageController animated:YES]; 
    [imageController release]; 
} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [[[UIApplication sharedApplication] keyWindow] setRootViewController:self.backupRootController]; 
    .... 
} 

espero que esta solución puede ayudar a otra persona en el futuro. --Goman

2

La única solución que funcionó para mí fue la categoría, pero que tenía que añadir otro método también:

#import "UIImagePickerController+NoRotate.h" 

@implementation UIImagePickerController (NoRotate) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
@end 

Salud!

0
-(BOOL)shouldAutorotate { 
return NO;} 

Pruebe esto en su controlador de vista. Esto funcionó para mí. Nota: Esto es para ios6.0 y por encima de

3

O bien, puede subclase el UIImagePickerController:

crear una nueva clase UIImagePickerController y sólo tiene que añadir estas líneas a la misma.

- (BOOL)shouldAutorotate{ 
return NO; 
} 

importación a la clase que utiliza la cámara y en lugar de utilizar por defecto UIImagePickerController, utilizar la clase que ha creado.

La cámara en sí debe detenerse de la rotación automática.

0

no hay necesidad de crear una subclase, basta con crear una categoría para UIImagePickerController y poner esta línea en él - (BOOL) shouldAutorotate { retorno NO; }

Cuestiones relacionadas