vuelta voltear voltea selfies selfie resolucion que porque modo las hacer frontal fotos espejo den configurar configuracion como camara ios iphone objective-c camera uiimagepickercontroller

ios - voltear - cámara iPhone, cómo evitar la visualización de la cámara en la vista previa; ¿Cómo saber cuándo se ingresa la vista previa?



selfie modo espejo iphone (4)

@ jerik-Vi que enmendó su pregunta. Puede configurar la propiedad showsCameraControls en no, lo que eliminará la pantalla de vista previa, esto también oculta los controles predeterminados (y le permite tomar varias fotos sin quitar la cámara), pero ya que está usando cameraOverlayView , es inmaterial. Esto solo funciona si el tipo de medio es una cámara, y deberá implementar la función takePicture del protocolo UIImagePickerDelegate para tomar la imagen de forma programática.

No he probado el truco de cambiar los controles de la pantalla de vista previa. Si realmente desea mantener la pantalla de vista previa, debe agregar lógica a su propia función takePhoto que determina si debe llamar a picker.cameraOverlayView = [self addCameraRollButton] (tomar una foto) o no (la pantalla de vista previa), pero I '' No estoy seguro si puede cambiar la cámaraOverlayView para la pantalla de vista previa dinámicamente, parece que Apple no querría que se metiera con usted. ¡En fin, buena suerte!

En el flujo de trabajo de la cámara, la foto se captura y en la siguiente pantalla, llamémosla elegir pantalla , puede elegir si desea usar esta foto o volver a tomarla.

¿Cómo sé que la cámara entra en la vista previa ?

Mi problema es que he agregado un botón para acceder al rodillo de la cámara, que funciona bien. El obstáculo es que, al tomar una foto e ingresar a la vista previa (2. Vista de la cámara), el botón oculta la opción "usar foto". Entonces no puedo seleccionarlo Quiero ocultar el botón al ingresar a la vista previa o simplemente evitar la vista previa .

Debajo de mi código

CamViewScreen.h

#import <UIKit/UIKit.h> #import "CameraViewController.h" #import <AssetsLibrary/AssetsLibrary.h> @interface CamViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> @property (nonatomic, strong) UIImage *image; @property (nonatomic, strong) UIImage *lastTakenImage; - (IBAction)takePhoto:(id)sender; - (IBAction)selectPhoto:(id)sender; @end

CamViewScreen.m

#import "CamViewController.h" @interface CamViewController () @end @implementation CamViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } int isAction = 0; // Photo, 1: CameraRoll, 2: Cancel - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device has no camera" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [myAlertView show]; } isAction = 0; [self cameraRoll]; } -(void)viewDidAppear:(BOOL)animated { // isAction = 0 Photo, 1: CameraRoll, 2: Cancel DLog(@"###### isAction> %d", isAction); switch (isAction) { case 1: [self selectPhoto:nil]; break; case 2: [self dismissViewControllerAnimated:NO completion:nil]; break; default: [self takePhoto:nil]; break; } } - (IBAction)takePhoto:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = NO; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.cameraOverlayView = [self addCameraRollButton]; // suggestion from omz // [self addCameraRollButton:picker.view]; [self presentViewController:picker animated:YES completion:NULL]; } -(void)prepareCameraRoll { isAction = 1; [self dismissViewControllerAnimated:NO completion:nil]; } - (IBAction)selectPhoto:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:YES completion:NULL]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; self.image = chosenImage; isAction = 0; [picker dismissViewControllerAnimated:YES completion:NULL]; [self performSegueWithIdentifier:@"toCameraView" sender:info]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { isAction = 2; // Cancel [picker dismissViewControllerAnimated:YES completion:NULL]; } # pragma mark - for the cameraOverlayView // suggestion from omz - (UIView *)addCameraRollButton { float startY = ([[UIScreen mainScreen] bounds].size.height == 568.0) ? 500.0 : 410.0; UIButton *rollButton = [UIButton buttonWithType:UIButtonTypeCustom]; rollButton.frame = CGRectMake(230.0, startY, 60.0, 60.0); rollButton.backgroundColor = [UIColor clearColor]; [rollButton setImage:self.lastTakenImage forState:UIControlStateNormal]; rollButton.imageView.contentMode = UIViewContentModeScaleAspectFill; [rollButton addTarget:self action:@selector(prepareCameraRoll) forControlEvents:UIControlEventTouchUpInside]; return rollButton; } # pragma mark - CameraRoll function and presentation - (void)addCameraRollButton:(UIView *)picker { float startY = ([[UIScreen mainScreen] bounds].size.height == 568.0) ? 500.0 : 410.0; UIButton *rollButton = [UIButton buttonWithType:UIButtonTypeCustom]; rollButton.frame = CGRectMake(230.0, startY, 60.0, 60.0); rollButton.backgroundColor = [UIColor clearColor]; [rollButton setImage:self.lastTakenImage forState:UIControlStateNormal]; rollButton.imageView.contentMode = UIViewContentModeScaleAspectFill; [rollButton addTarget:self action:@selector(prepareCameraRoll) forControlEvents:UIControlEventTouchUpInside]; [picker addSubview:rollButton]; } -(void)cameraRoll { ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (nil != group) { // be sure to filter the group so you only get photos [group setAssetsFilter:[ALAssetsFilter allPhotos]]; [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { if (asset) { ALAssetRepresentation *repr = [asset defaultRepresentation]; // UIImage *img = [UIImage imageWithCGImage:[repr fullResolutionImage]]; UIImage *img = [UIImage imageWithCGImage:[repr fullScreenImage]]; [self setLastTakenImage:img]; *stop = YES; } }]; } *stop = NO; } failureBlock:^(NSError *error) { NSLog(@"error: %@", error); }]; } #pragma mark - Navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { CameraViewController *cvc = [segue destinationViewController]; cvc.image = self.image; DLog(@"%@, cvcimage", cvc.image); } @end


En veloz 4 para referencias futuras. Estoy usando isHidden porque tuve problemas para mostrarlo cuando el usuario selecciona Retake.

NotificationCenter.default.addObserver(forName: Notification.Name("_UIImagePickerControllerUserDidCaptureItem"), object: nil, queue: nil) { _ in overlayView.isHidden = true overlayView.isUserInteractionEnabled = false } NotificationCenter.default.addObserver(forName: Notification.Name("_UIImagePickerControllerUserDidRejectItem"), object: nil, queue: nil) { _ in overlayView.isHidden = false overlayView.isUserInteractionEnabled = true }


Encontré una solución. Fue difícil de encontrar, pero finalmente lo consiguió. La solución se describe en UIImagePicker cameraOverlayView aparece en la pantalla Volver a tomar . Además agrego mi código de trabajo para otros que tienen el mismo problema.

El uso de NSNotificationCenter con @ "_ UIImagePickerControllerUserDidCaptureItem" y @ "UIImagePickerControllerUserDidRejectItem" es la clave.

CamViewController.h

#import <UIKit/UIKit.h> #import "CameraViewController.h" #import <AssetsLibrary/AssetsLibrary.h> @interface CamViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> @property (nonatomic, strong) UIImage *image; @property (nonatomic, strong) UIImage *lastTakenImage; @property (nonatomic, strong) UIImagePickerController *picker; - (IBAction)takePhoto:(id)sender; - (IBAction)selectPhoto:(id)sender; @end

CamViewController.h

#import "CamViewController.h" @interface CamViewController () @end @implementation CamViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } int isAction = 0; // Photo, 1: CameraRoll, 2: Cancel - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"_UIImagePickerControllerUserDidCaptureItem" object:nil ]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"_UIImagePickerControllerUserDidRejectItem" object:nil ]; [super viewDidLoad]; if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Device has no camera" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [myAlertView show]; } isAction = 0; [self cameraRoll]; } -(void)handleNotification:(NSNotification *)message { if ([[message name] isEqualToString:@"_UIImagePickerControllerUserDidCaptureItem"]) { // Remove overlay, so that it is not available on the preview view; self.picker.cameraOverlayView = nil; } if ([[message name] isEqualToString:@"_UIImagePickerControllerUserDidRejectItem"]) { // Retake button pressed on preview. Add overlay, so that is available on the camera again self.picker.cameraOverlayView = [self addCameraRollButton]; } } -(void)viewDidAppear:(BOOL)animated { // isAction = 0: Photo, 1: CameraRoll, 2: Cancel DLog(@"###### isAction> %d", isAction); switch (isAction) { case 1: [self selectPhoto:nil]; break; case 2: [self dismissViewControllerAnimated:NO completion:nil]; break; default: [self takePhoto:nil]; break; } } - (IBAction)takePhoto:(id)sender { self.picker = [[UIImagePickerController alloc] init]; self.picker.delegate = self; self.picker.allowsEditing = YES; // if this is NO or missing, the image the image will not be in info[UIImagePickerControllerEditedImage] self.picker.sourceType = UIImagePickerControllerSourceTypeCamera; self.picker.cameraOverlayView = [self addCameraRollButton]; [self presentViewController:self.picker animated:YES completion:NULL]; } -(void)prepareCameraRoll { isAction = 1; [self dismissViewControllerAnimated:NO completion:nil]; } - (IBAction)selectPhoto:(id)sender { self.picker = [[UIImagePickerController alloc] init]; self.picker.delegate = self; self.picker.allowsEditing = YES; self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:self.picker animated:YES completion:NULL]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { self.image = info[UIImagePickerControllerEditedImage]; isAction = 0; [picker dismissViewControllerAnimated:YES completion:NULL]; [self performSegueWithIdentifier:@"toCameraView" sender:info]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { isAction = 2; // Cancel [picker dismissViewControllerAnimated:YES completion:NULL]; } # pragma mark - CameraRoll function and presentation - (UIView *)addCameraRollButton { float startY = ([[UIScreen mainScreen] bounds].size.height == 568.0) ? 500.0 : 410.0; UIButton *rollButton = [UIButton buttonWithType:UIButtonTypeCustom]; rollButton.frame = CGRectMake(230.0, startY, 60.0, 60.0); rollButton.backgroundColor = [UIColor clearColor]; [rollButton setImage:self.lastTakenImage forState:UIControlStateNormal]; rollButton.imageView.contentMode = UIViewContentModeScaleAspectFill; [rollButton addTarget:self action:@selector(prepareCameraRoll) forControlEvents:UIControlEventTouchUpInside]; return rollButton; } -(void)cameraRoll { // have to import assetlibrary framework!!! ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (nil != group) { // be sure to filter the group so you only get photos [group setAssetsFilter:[ALAssetsFilter allPhotos]]; [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { if (asset) { ALAssetRepresentation *repr = [asset defaultRepresentation]; // UIImage *img = [UIImage imageWithCGImage:[repr fullResolutionImage]]; UIImage *img = [UIImage imageWithCGImage:[repr fullScreenImage]]; [self setLastTakenImage:img]; *stop = YES; } }]; } *stop = NO; } failureBlock:^(NSError *error) { NSLog(@"error: %@", error); }]; } #pragma mark - Navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { CameraViewController *cvc = [segue destinationViewController]; cvc.image = self.image; DLog(@"%@, cvcimage", cvc.image); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end


Solo publique aquí para futuras referencias de Swift, si alguien lo necesita.

He estado teniendo el mismo problema, y ​​después de un día de investigación, con muchos rastros y errores, encontré una manera de eliminar la cámara Vista de la vista previa de la imagen.

Cuando toma una fotografía, se activa el "_UIImagePickerControllerUserDidCaptureItem". Afortunadamente podemos utilizar esto creando un observador con un cierre. Dentro del cierre, podemos configurar cameraOverlayView en cero y, por lo tanto, eliminar su vista personalizada antes de ingresar a la vista previa.

Esto funciona en Xcode Versión 8.1 (8B62), con Swift 3.

He agregado el fragmento de código para que lo utilice si es necesario.

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "_UIImagePickerControllerUserDidCaptureItem"), object:nil, queue:nil, using: { note in self.imagePicker.cameraOverlayView = nil )}