Custom shape for camera controller IOS - 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);

Related

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."];
}

UIImagePickerController doesn't fit into the window when presented

I am trying to develop a simple application which is going to work with the photos the user takes. By following https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html I am using a UIImagePickerController in order to take the snapshot. I have a basic application with a single, empty view controller and in the viewDidAppear method I do the following:
- (void)viewDidAppear:(BOOL)animated
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Error" message: #"Can't use the camera!" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
[self presentViewController: cameraUI animated: YES completion:NULL];
}
The resulting view becomes something like:
As you can see the front-rear camera change button doesn't show completely and the UIImagePickerController does not fit into the screen. Should I additionally resize before presenting or am I doing something incorrectly?

UIImagePickerController in subview >not fullscreen

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.

iPhone camera controls are misaligned

For some reason my camera controls are misaligned and are displaying cut off at the top of the screen. Below is the code that I've implemented to use the camera, is there anything that could fix this?
- (void)takePhoto {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[MAINVIEWCONTROLLER presentViewController:picker animated:YES completion:nil];
}
check wantsFullScreenLayout and set it accordingly.
If you want full screen, you will also need to hide the status bar using setStatusBarHidden:withAnimation:

Using GKImagePicker to crop photo

I want to crop a photo that is taken in the app and then save. I am using the GKImagePicker so that I can do this but if I use the code below even though I push the take photo button in my app it shows me the photo library which I pick to crop. I do not want to do this and just want to crop my photo which I have taken in the app.
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 320);
self.imagePicker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:self.imagePicker.imagePickerController animated:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
Remove the last line in your code:
[self presentViewController:picker animated:YES completion:NULL];// remove
and give it a try ;)
You can also check this.

Resources