UIImagePickerController in subview >not fullscreen - ios

I'm trying to add UIImagePickerController into my rootviewcontroller as a subview, so that the camera is displayed within the main app area, not as an overlay.
Here is my code:
-(void)cameraSetup{
CGRect bottomBarFrame = CGRectMake(0, self.view.frame.size.height-UA_BOTTOM_BAR_HEIGHT, self.view.frame.size.width, UA_BOTTOM_BAR_HEIGHT);
self.bottomNavBar = [[BottomNavBar alloc] initWithFrame:bottomBarFrame leftIcon:UA_ICON_PHOTOLIBRARY withFrame:CGRectMake(0, 0, 45, 22.5) centerIcon:UA_ICON_TAKE_PHOTO withFrame:CGRectMake(0, 0, 90, 45)];
//create a new image picker instance
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//set source to video!
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = NO;
picker.toolbarHidden = YES;
picker.editing = NO;
//make the video preview full size
//picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform,1, 1);
[picker.view addSubview:self.bottomNavBar];
picker.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-(UA_TOP_WHITE+UA_TOP_WHITE-bottomBarFrame.size.height));
[self.view addSubview:picker.view];
[picker viewWillAppear:YES];
[picker viewDidAppear:YES];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Test Text" message:#"Camera is Not Availble" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert show];
}
}
even though I'm setting the frame of the picker not to be full-screen it always appears full-screen. is there any way to get rid of that behavior? or is there another option to display my BottomNavBar on top of the picker?

UIImagePickerController is intended for use when an application requires access to system resources, like the camera or even the users photo library. As they UIImagePickerController enables system access in a controlled manner, it is obvious you cannot customize it.

Related

UIImagePickerController Above UIAlertView

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.

iOS: Overlay on iPhone Camera Preview

I'm using Camera API and invoking the camera.
I want to display a header (for branding) on the top of the camera preview. The header is a png image.
Is it possible? Any help appreciated.
Thanks in advance.
You set overlay view of camera.
Check below link. It will help you the solve the problem.
https://stackoverflow.com/a/8101616/1850983
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPickerCamera = [[UIImagePickerController alloc] init];
self.imgPickerCamera.delegate = self;
self.imgPickerCamera.allowsEditing = YES;
self.imgPickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPickerCamera.navigationBarHidden = NO;
UIImageView *imageView = [[UIImageView alloc] initWithImage:#"<Your image>"];
imageView.frame = <set frame>;
//setting navigation bar
self.imgPickerCamera.navigationController.navigationItem.titleView = imageView;
// Insert the overlay: OverlayView is a UIView
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,1024) withImagePicker:self.imgPickerCamera];
self.imgPickerCamera.cameraOverlayView = overlay;
[self presentViewController:self.imgPickerCamera animated:YES completion:NULL];
} else {
[self showAlertWithOKButton:#"Error" message:#"Your device doesn't have camera."];
}

How to create GalleryShortcut when presenting UIImagePickerController

I want to give option for user to take a photo or upload one as his avatar in my app.
I believe there is no need to put two different buttons for that, so instead I would like to make the next scenario:
user clicks on "Add Picture" button and automatically UIImagePicker with source control - camera is presented.
But, I want to have shortcut for gallery in the corner, where user could click, get into gallery and search for pic he would use.
Here is the screenshot of what I need:
Part with red circle is important part.
How do I put it there?
(Initially it's not there)
There is no pre-build way to do this.
What you can do is to make an overlay for Camera View.
Bear in mind that you have to make different view for each device, as every device already has different positioning inside the CameraView.
One example would be this:
- (IBAction)addImage:(UIButton *)sender {
UIView* overlay = [[UIView alloc] initWithFrame:CGRectMake(20,self.view.frame.size.height-60 , 40, 40)];
overlay.opaque=NO;
overlay.backgroundColor = [UIColor clearColor];
UIButton* btnGallery = [[UIButton alloc]initWithFrame:CGRectMake(0,0 , 40, 40)];
[btnGallery setImage:[UIImage imageNamed:#"image_gallery"] forState:UIControlStateNormal];
btnGallery.backgroundColor = [UIColor whiteColor];
[overlay addSubview:btnGallery];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = YES;
[imagePicker.view addSubview:overlay];
[btnGallery addTarget:self
action:#selector(openGallery)
forControlEvents:UIControlEventTouchUpInside];
_picker = imagePicker;
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)openGallery
{
UIImagePickerController *gallery = [[UIImagePickerController alloc] init];
gallery.delegate = self;
gallery.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
gallery.mediaTypes = #[(NSString *) kUTTypeImage];
gallery.allowsEditing = YES;
_gallery = gallery;
[_picker presentViewController:gallery
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];

Custom shape for camera controller IOS

I am trying to give a round shape to the camera view to take an image. The circle should be of 200 width and 200 height, and when it is open, the user has to be able to still interact with background view. All I have managed until now is:
- (IBAction)useCameraPhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker
animated:YES completion:nil];
newMedia = YES;
}else{
NSLog(#"Camera is not available");
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:#"Important message" message:#"Unfortunately the camera is not available on your device." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert1 show];
}
}
This code is presenting a viewcontrller from where users can take a shot, but it does not have a round shape.
I thought of doing something like
imagePicker.allowsEditing.frame = CGRectMake (30, 100, 200, 200);
but still this would not give it the round corners. Furthermore the view beneath it, even if visible, does not respond to touch. Any ideas?
EDIT:
I have tried this. It gives round corners but the background is still black
imagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
imagePicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker.view.layer.cornerRadius = 100; // this value vary as per your desire
imagePicker.view.clipsToBounds = YES;
imagePicker.view.frame = CGRectMake(40,40, 200, 200);
Instead of doing a modal pop-up, you can directly add camera support using the AVFoundation. There is a nice iOS camera demo already available for free on the apple developer site.
Then you can attach the preview image to a UIImageView on your UIViewController and do the same thing with its layer to get the desired effect:
imageView.view.layer.cornerRadius = 100; // this value vary as per your desire
imageView.view.clipsToBounds = YES;
imageView.view.frame = CGRectMake(40,40, 200, 200);

Resources