UIImagePickerController Shutter

I have a bug with the UIImagePickerController the source of which is the camera. Sometimes after the controller appears, the shutter does not open, and I do not see the video signal of the camera, but the photo taken is correct. enter image description here

Maybe I'm doing something wrong? Code:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){ UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init]; cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; cameraUI.allowsEditing = NO; cameraUI.showsCameraControls = NO; cameraUI.delegate = self; NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil]; UIView *controlsView = [nibObjects objectAtIndex:0]; CGRect overlayViewFrame = cameraUI.cameraOverlayView.frame; CGRect controlsFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - 54.0, CGRectGetWidth(overlayViewFrame), 54.0); controlsView.frame = controlsFrame; [cameraUI.cameraOverlayView addSubview:controlsView]; [self presentModalViewController: cameraUI animated: YES]; } 
+4
source share
3 answers

The same thing happened to me after locking / unlocking the application, it seems that the shutter opens on viewDidAppear.

So, I subscribed my parent view controller to UIApplicationDidBecomeActiveNotification and manually re-executed the viewWillAppear and viewDidAppear methods of the controller containing the UIImagePickerController

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; . . . - (void)applicationBecomeActive { if (imagePicker_) [imagePicker_ openShutter]; } 

And then on the controller containing the UIImagePickerController

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [imagePickerController_ viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [imagePickerController_ viewDidAppear:animated]; imagePickerController_.cameraFlashMode = cameraFlashMode_; imagePickerController_.cameraDevice = cameraDevice_; } - (void)openShutter { [imagePickerController_ viewWillAppear:YES]; [imagePickerController_ viewDidAppear:YES]; } 

PS: If you try this, do not forget to remove the observer

 [[NSNotificationCenter defaultCenter] removeObserver:self]; 

Hope this helps

+1
source

If you are presenting the UIImagePickerController non-modally (the recommended path), you can either call viewDidAppear and willAppear manually, or add the UIImagePickerController as the child view controller from where you present.

 [thePresentingViewCotnroller addChildViewController:imagePickerController]; 

after that you can add the view from imagePickerController as a subheading, this will automatically call the view lifecycle methods ( viewWillAppear, didAppear and disappear ).

+1
source

Try adding auto-release when initializing the UIImagePickerController :

 UIImagePickerController *pickerController = [[[UIImagePickerController alloc] init] autorelease]; 
-one
source

Source: https://habr.com/ru/post/1392853/


All Articles