Hide UIPopoverController background - ios

I am loading a UIPopoverController that contains a UIImagePickerController, when the view loads it loads a seethrough view behind the popover, which if touched it dismisses the popover and the the cameraview inside it.
I would like to know if there is a way to remove this background view and control the dismiss myself with buttons.
My goal is to have some information to the left and the camera popover view to the right, but I cannot do this as some of the information is selectable i.e. textfields, and currently this background view is preventing selection of them.
This is my code for the popovercontroller and the UIImagePickerController.
- (void) cameraButtonSelected
{
// set background
UIView *cameraBG = [[UIView alloc] initWithFrame:CGRectMake(0.0, 20.0, screenHeight, screenWidth-64)];
cameraBG.backgroundColor = [UIColor blackColor];
cameraBG.alpha = 0.8;
[self.view addSubview:cameraBG];
// create picker
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
CGFloat scaleFactor=1.3f;
picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);
}
// create popover
self.popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
[self.popOver presentPopoverFromRect:CGRectMake(500, 100, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:NO];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
viewController.preferredContentSize = CGSizeMake(805, 650);
}

You can just call,
self.popOver.hidden = YES; or self.popOver.hidden = NO;
If you want the pop0ver view to still be drawn but still hidden to the user, you can call self.pop0ver.alpha = 0.0f;

Related

iOS, PopOverPresentationController issue, .xib

I have a NavigationController, another controller was pushed on its stack: BNRDetailsViewController. Now, inside BNRDetailsViewController I am trying to show a popover window when pressing on a toolbar button, that would present me with UIImagePickerController (only on iPad devices). So, I tried to follow the following stackoverflow thread:
UIPopoverPresentationController on iOS 8 iPhone
But no success. If I just use their code I get an error that says, that pushing navigationController is not supported. If I try to push the newly created UIPopoverPresentationController like this: [self.navigationController pushViewController:self.imagePickerPopover animated:YES]; it crashes because UIPopoverPresentationController is not of type UIViewController, so, I guess, I can not just push it on the stack.
What would you suggest to do in this particular case?
Here is the code which I have right now that is triggered when the toolbar button is pressed:
- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If the device have camera, take a picture, otherwise,
// just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
//[self presentViewController:imagePicker animated:YES completion:NULL];
// Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagePicker
_imagePickerPopover = [[UIPopoverPresentationController alloc] initWithPresentedViewController:imagePicker presentingViewController:self];
imagePicker.preferredContentSize = CGSizeMake(280, 200);
_imagePickerPopover.delegate = self;
_imagePickerPopover.sourceView = self.view;
CGRect frame = [[sender valueForKey:#"view"] frame];
frame.origin.y = frame.origin.y + 20;
_imagePickerPopover.sourceRect = frame;
// [self.navigationController pushViewController:self.imagePickerPopover animated:YES];
}
}
Here is the code, based on your code, that will get the popover to display on the iPad.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
imagePicker.modalPresentationStyle = UIModalPresentationPopover;
imagePicker.preferredContentSize = CGSizeMake(280, 200);
CGRect frame = [[sender valueForKey:#"view"] frame];
frame.origin.y = frame.origin.y + 20;
UIPopoverPresentationController *popoverController =
imagePicker.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = frame;
[self.navigationController presentViewController:imagePicker
animated:YES completion:nil];
}

UIImagePickerController dismissing when it shouldn't

I am trying to create a custom camera overlay, but am having some problems. The capture view works great, but I would like to show another view where the user can edit the photo after the image is captured. The problem is that when a photo is taken, the view with the photo is automatically dismissed. How would I fix this so that I can show another view controller after the user takes a photo.
Here is how I create the picker:
self.cameraPicker = [[UIImagePickerController alloc] init];
self.cameraPicker.delegate = self;
self.cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPicker.showsCameraControls = NO;
self.cameraPicker.allowsEditing = YES;
self.cameraPicker.navigationBarHidden = YES;
self.cameraPicker.toolbarHidden = YES;
self.cameraPicker.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
self.frontFacing = NO;
self.gridShowing = NO;
self.showingFlash = NO;
// Insert the overlay
CameraOverlayView *overlay = [[CameraOverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
self.cameraPicker.cameraOverlayView = overlay;
overlay.delegate = self;
[self.navigationController presentViewController:(UIViewController *)self.cameraPicker animated:YES completion:nil];
Here is how I take the photo, after this is called, the viewController is dismissed:
, which I do not want:
[self.cameraPicker takePicture];

UIPopoverController presentPopoverFromRect not displaying correctly

I am loading a popover view that displays the camera view. everything works however it dose not dsplay any bigger than a playing card on the iPad. No matter what I do I cannot resize it only change its position.
This is the code I use
[self.popOver presentPopoverFromRect:CGRectMake(44, 6, 111, 111) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
How can I adjust the size?
Update
This is what my whole method looks like:
- (void) cameraButtonSelected
{
// create picker
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.preferredContentSize = CGSizeMake(400.0, 400.0);
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
CGFloat scaleFactor=1.3f;
picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);
}
// create popover
self.popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
[self.popOver presentPopoverFromRect:CGRectMake(44, 6, 111, 111) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
try settings this property to the controller contained in popover
someViewController.contentSizeForViewInPopover = CGSizeMake(200.0, 200.0)
try using
preferredContentSize
property.
sorry I don't have a mac on me to check it
You should try to set the size in viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.popover.preferredContentSize = ...
}
Nothing worked for me, so I resized the popoverController after displaying it like this:
[popoverController presentPopoverFromRect:cell.mediaComment.frame
inView:cell
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
popoverController.contentViewController.preferredContentSize = REQUIRED_RECT.size;
popoverView.frame = REQUIRED_RECT;
});

Dismissing custom UIImagePickerController

I am loading a UIImagePickerController in this way:
- (void) launchCamera {
// Set up the camera
CustomCamera *cameraController = [[CustomCamera alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;
cameraController.showsCameraControls = NO;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;
// overlay on top of camera lens view
UIImageView *cameraOverlayView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"camera_overlay.png"]];
cameraOverlayView.alpha = 0.0f;
cameraController.cameraOverlayView = cameraOverlayView;
// animate the fade in after the shutter opens
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:2.2f];
cameraOverlayView.alpha = 1.0f;
[UIView commitAnimations];
[self presentModalViewController:cameraController animated:YES];
}
The problem is that I don't know how to dismiss it. When I try
[cameraController dismissViewControllerAnimated:YES completion: nil];
I get a red error. The cameraController is just a UIImagePickerController
It is because the cameraController did not do a presentation, the self object did. You are calling self present instead of cameraController

How to change the bar color in UIImagePicker?

I am trying to color the bars in the camera view black. None of the below approaches worked so far. There are 2 views that I want to change, the first with the camera icon and "cancel", the second with the "retake" and "use" buttons. Any ideas?
- (void)openCamera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.toolbar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.tintColor = [UIColor blackColor];
[self presentModalViewController:picker animated:NO];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIImagePickerController *picker = (UIImagePickerController *)navigationController;
if((picker)&&(picker.sourceType == UIImagePickerControllerSourceTypeCamera))
{
picker.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.tintColor = [UIColor blackColor];
}
}
You might have some luck using UIAppearance. Look up the documentation.
You can use the UIImagePickerController showsCameraControls and cameraOverlayView to use a custom view over the UIImagePickerController. Setting the showsCameraControlsvalue to NO will hide everything on the UIImagePickerController but the camera view. cameraOverlayView allow you to put your own view over the camera view. You can then create a view with your own bottom bar, your own buttons, ... and put it in front of the UIImagePicker.
UIView *overlayView = [[UIView alloc] init];
/* Customize overlayView with your bottomBar and button */
UIImagePickerController imagePickerController = [[UIImagePickerController alloc] init];
/* Configure your UIImagePickerController for picture and/or video */
imagePickerController.showsCameraControls = NO; //Must be set to NO if you want to use the cameraOverlayView
imagePickerController.cameraOverlayView = overlayView;
overlayView = nil;
Unfortunately, with this method you must recreate all the buttons of the original UIImagePickerController view (the flash mode button, the options button, ...) if you want to use them, and you have to create your own navigation controller to go to the view with the "retake" and "use" buttons. However it's very simple to implement.

Resources