I'm adding UIImagePickerController as a subview of my UINavigationController which is inside a UIPopoverController.
Heres the code:
UIViewController *container = [[UIViewController alloc] init];
self.navigationBarHidden = YES;
camera = [[UIImagePickerController alloc] init];
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
[container addChildViewController:camera];
[container.view setFrame:camera.view.frame];
[container.view addSubview:camera.view];
[self pushViewController:container animated:YES];
Everything looks great but the shutter animation. It seems to be off center, where the middle of the iris is actually hitting the top of the view.
How do I fix the shutter animation?
Related
I'm developing an Application in which I need the UIAlertView to be present in the background while UIImagePickerController is presenting the camera. Currently, the UIAlertView is displayed as a superview (above the camera) when camera controller is presented.
Ideas are appreciated.
AlertViews are added to the window and not the controller. They will always be on the top. you can present the picker in an alertview to overlap it.
you can use this library
https://github.com/wimagguc/ios-custom-alertview
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.showsCameraControls = NO;
CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
[container addSubview:cameraView.view];
container.subviews.lastObject.center = CGPointMake(container.subviews.lastObject.center.x, container.center.y);
[alertView setContainerView:container];
[alertView setDelegate:self];
// Display the dialog
[cameraView viewWillAppear:YES]; // trickery to make it show
[cameraView viewDidAppear:YES];
[alertView show];
You can show alertView and then present ImagepickerController. So when you dissmiss that imagePickerController you alertView will there on viewController.
I'm fairly new to Objective-C and I'm trying to get a button pressed event to trigger on a button that is on a custom view that is being overlaid on a UIImagePicker.
I connect the button to an IBAction on the overlaid view, but when I press the button I get a bad access error.
here is the code I am using to for the overlay:
// prepare imagePicker view
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
imagePicker.showsCameraControls = NO;
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
// prepare custom view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
#"Main" bundle:[NSBundle mainBundle]];
UIViewController *overlay = [storyboard instantiateViewControllerWithIdentifier:#"overlayView"];
imagePicker.cameraOverlayView = overlay.view;
// display imagePicker
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
can you try to make UIImagePickerController *imagePicker as a property
#property (nonatomic) UIImagePickerController *imagePicker;
then
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.showsCameraControls = NO;
Good luck
You should have the buttons point to a method on the presenting viewController. Maybe adding the overlay as a childViewController to the imagePicker would solve your problem, but the cameraOverlayView should be just a view.
Here's a good implementation of what you're trying to do: Using cameraOverlayView with UIImagePickerController
UPDATE: Keep a weak reference to overlayView from your presenting View Controller through a property such as:
#property (weak) OverlayView *overlayView;
and in your code:
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height);
imagePicker.cameraOverlayView = [[OverlayView alloc] initWithFrame:overlayRect];
// Hold a weak reference to the `cameraOverlayView`
self.overlayView = (OverlayView *)imagePicker.cameraOverlayView;
now the presenting viewController can access self.overlayView's public properties when the imagePicker is alive. Make sure you check if self.overlayView before trying to access its properties.
How do I make my flip animation transparent so the view behind it is shown through?
Here's some of my code:
EditInfoViewController *editController = [[EditInfoViewController alloc] initWithNibName:#"EditInfoViewController" bundle:nil];
editController.delegate = self;
UINavigationController *editNavController = [[UINavigationController alloc] initWithRootViewController:editController];
editNavController.modalPresentationStyle = UIModalPresentationCurrentContext;
editNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:editNavController animated:YES];
A picture is worth 1000 words (this was taken during the flip animation):
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.
I have seen other posts on this subject, but no valid solutions. Surely this is possible! I found one solution here that suggests presenting it from a container view controller. The code for that is commented out in my method below. This DOES create the fullscreen view, but the cancel/take photo buttons won't work then, and I can't seem to dismiss it properly. Is there really no simple elegant solution to this???? Please help! Here's my code:
-(IBAction)launchCamera:(id)sender
{
[self.popoverController dismissPopoverAnimated:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//fullScreenViewController = [[UIViewController alloc] init];
//fullScreenViewController.contentSizeForViewInPopover = CGSizeMake(768, 1024);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Tried making the view full screen (or at least larger), but doesn't work...
//popoverController.contentViewController.contentSizeForViewInPopover = CGSizeMake(384, 512);
[imagePicker setTitle:#"camera"];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
//[fullScreenViewController.view addSubview:imagePicker.view];
// change imagePicker to fullScreenViewController here for full screen:
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popoverController setDelegate:self];
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
I never could make the UIImagePicker work properly in full-screen, so I ended up using the AVFoundation framework to implement my own.