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
Related
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];
}
It is an iPhone app and I have an assistant view which is always on top of the window(can expand and minimise). There are a few buttons inside the view that allow me to switch between capturing image, capturing video and recording audio. In app delegate it looks like:
[self.window addSubview:assistantFloatingViewController.view];
[self.window makeKeyAndVisible];
self.window.frame = [UIScreen mainScreen].bounds;
Then add UIImagePickerController when click capture image button inside the assistant view:
- (void)presentImagePicker{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = #[(__bridge NSString *) kUTTypeImage];
[self moveFromViewController:self.currentContentViewController ToViewController:imagePickerController];
self.currentContentViewController = imagePickerController;
}
- (void)moveFromViewController:(UIViewController *)fromVC ToViewController:(UIViewController *)toVC {
[fromVC willMoveToParentViewController:nil];
[self addChildViewController:toVC];
[fromVC.view removeFromSuperview];
[fromVC removeFromParentViewController];
[self.view addSubview:toVC.view];
[toVC.view alignToView:self.containerView];
[toVC didMoveToParentViewController:self];
self.currentContentViewController = toVC;
}
The problem is after I took an image, Retake and User Photo buttons cannot be tapped (no response ).
What have I done wrong here? Any help will be appreciated!
Replace last two line of your code
[self moveFromViewController:self.currentContentViewController ToViewController:imagePickerController];
self.currentContentViewController = imagePickerController;
with this one,
[self presentViewController:imgPicker animated:YES completion:^{
// Your code
}];
I have code that perfectly works on iPad
self.clockInEmployee = nil;
self.clockInEmployee = [[userInfo userInfo] valueForKey:#"employee"];
self.clockInEmployeeRole = [[userInfo userInfo] valueForKey:#"role"];
CLog (#"PIN %#", self.clockInEmployee.pin);
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = (id)self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.cameraOverlayView = self.cameraOverlay.view;
if (isPhone())
{
picker.view.frame = CGRectMake(0, 748, 1024, 748);
[mainNavController.view addSubview:picker.view];
[UIView animateWithDuration:0.5 animations:^{
picker.view.frame = CGRectMake(0, 0, 1024, 748);
} completion:^(BOOL finished){
[picker viewDidAppear:YES];
}];
}
modViewController = picker;
but on iPhone when it try to launch camera I only observe black screen.
But if I try to launch it like that:
[appPresentingViewController presentViewController:picker animated:YES completion:nil];
it launches successfully. But in my particular project it causes some UI problems, so it can't be used.
How can I make this
if (isPhone())
{
picker.view.frame = CGRectMake(0, 748, 1024, 748);
[mainNavController.view addSubview:picker.view];
[UIView animateWithDuration:0.5 animations:^{
picker.view.frame = CGRectMake(0, 0, 1024, 748);
} completion:^(BOOL finished){
[picker viewDidAppear:YES];
}];
}
work for both iPad and iPhone ?
Please try this:-
//create an overlay view instance
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
//create a new image picker instance
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
//set source to video!
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
//make the video preview full size
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform =
CGAffineTransformScale(picker.cameraViewTransform,
CAMERA_TRANSFORM_X,
CAMERA_TRANSFORM_Y);
//set our custom overlay view
picker.cameraOverlayView = overlay;
//show picker
[self presentModalViewController:picker animated:YES];
for further refrence -here
You may like to go through apples sample project of AVCAM it can be found here
what you need to do is something like this:
AVCaptureSession *avcam = [[AVCaptureSession alloc] init];
AVCaptureVideoPreviewLayer *previewLayer =
[AVCaptureVideoPreviewLayer layerWithSession:avcam];
previewLayer.frame = self.previewView.bounds;
[self.previewView.layer addSublayer:previewLayer];
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];
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;