I have been searching for a while and can not seem to find a clear way of doing this. Any link I did find is outdated. I am presenting a camera like so
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//Get the camera
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
self.imagePicker.showsCameraControls = NO;
self.imagePicker.wantsFullScreenLayout = YES; //<-- This does not work in iOS7
//set our custom overlay view
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
I have a ViewController connected to an xib named ControllsViewController . I have no idea how to assign it to self.imagePicker.cameraOverlayView = . Can anyone help me here?
You need to instantiate the ControllsViewController using the xib. Assuming you have a xib file called "ControllsViewController" in your main bundle:
ControllsViewController *overlayViewController = [ControllsViewController alloc] initWithNibName:#"ControllsViewController" bundle:nil];
self.imagePicker.cameraOverlayView = overlayViewController.view;
You probably want to assign overlayViewController to a property to keep it around.
Related
In my app, the frame size of my UIDocumentPickerViewController always full screen as the following picture and the following code. However, I find there is a different frame size for the UIDocumentPickerViewController but I don't know how to get the effect as the second picture. Does anyone know how to get the effect?
https://drive.google.com/file/d/1_q_kfIIYA0d0KcT7NyPpFb6Q1vymU-lb/view?usp=sharing
- (void)btnPressDown {
NSLog(#"Press Down QQ");
[self showDocumentPickerInMode:UIDocumentPickerModeImport];
}
- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
NSLog(#"showDocumentPickerInMode QQ");
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.data"] inMode:mode];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
https://drive.google.com/file/d/177W-O0eJmePhLfS8ifGlw9n3jj26FDn9/view?usp=sharing
You need to set presentation style. The presentation style determines how a modally presented view controller is displayed onscreen.
"picker.modalPresentationStyle = UIModalPresentationFormSheet;"
- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.data"] inMode:mode];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
Thats it :)
I have a problem showing the album a toolbar with the following buttons, previous and the new one appears in the bottom view. How can you hide this toolbar?
Thanks in advance.
Album photo image
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
controller.allowsEditing = YES;
controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
controller.delegate = self;
[self.navigationController presentViewController: controller animated: YES completion: nil];
If you want to hide the toolbar you can use the following code . Here the toolBarName is the name of your toolbar.
toolBarName.hidden=YES;
Include this in the viewWillAppear function:
self.navigationController?.isToolbarHidden = true
However, this is a Swift solution.
Use this code.Hope it helps..
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init] ;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
imagePickerController.delegate = self;
imagePickerController.allowsEditing = FALSE;
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
NSZombie detected that one of the objected is over released in my app and that is causing the app to crash every time when a button is pressed. However, after inspecting the source code of where the over release happens, I couldn't see any obvious code that that may have caused the release. Can xcode release objects automatically without any actual code?
Below are the places reported by the Instrument that has a release event:
-(void) takePicture:(CDVInvokedUrlCommand *)command {
CDVCameraPicker* cameraPicker = [[CDVCameraPicker alloc] init];
self.pickerController = cameraPicker;
CameraOverlayViewController* overlay = [[CameraOverlayViewController alloc] initWithNibName:#"CameraOverlayViewController" bundle:nil];
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.cameraOverlayView = overlay.view;
[self.viewController presentViewController:cameraPicker animated:YES completion:nil];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
Any ideas on how to fix the problem? Thanks in advance!
I think CameraOverlayViewController is released.
Try the below code
CameraOverlayViewController* overlay;
-(void) takePicture:(CDVInvokedUrlCommand *)command {
CDVCameraPicker* cameraPicker = [[CDVCameraPicker alloc] init];
self.pickerController = cameraPicker;
overlay = [[CameraOverlayViewController alloc] initWithNibName:#"CameraOverlayViewController" bundle:nil];
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.cameraOverlayView = overlay.view;
[self.viewController presentViewController:cameraPicker animated:YES completion:nil];
}
You're creating a CameraOverlayViewController and keeping a reference to it's view, but the CameraOverlayViewController itself is going out of scope when the takePicture: method ends. A view doesn't retain it's view controller. You need to either keep a reference to the CameraOverlayViewController, or if you're only interested in the view object itself, just create a view from the xib file and set the cameraPicker.cameraOverlayView to that view.
EDIT:
For example, in your header file you could make a property:
#property (strong) CameraOverlayViewController *overlay;
and in your method:
-(void) takePicture:(CDVInvokedUrlCommand *)command {
CDVCameraPicker* cameraPicker = [[CDVCameraPicker alloc] init];
self.pickerController = cameraPicker;
self.overlay = [[CameraOverlayViewController alloc] initWithNibName:#"CameraOverlayViewController" bundle:nil];
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.cameraOverlayView = self.overlay.view;
[self.viewController presentViewController:cameraPicker animated:YES completion:nil];
}
Once you're done with the camera, you'll want to let go of the reference. So for example:
-(void) cameraPickerFinished {
self.overlay = nil;
}
How can I create the image picker in code?
I use iOS 6.0 , with ARC, for ipad.
I would like to able to select the picture and somehow get UIImage of the selected image.
i did add delegates:
enter code here
in the viewDidLoad method did
enter code hereimagePicker = [[UIImagePickerController alloc] init];
and in the button method for click i have put
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
the crash happens in
[self presentModalViewController:imagePicker animated:YES];
There are some tutorials here http://www.raywenderlich.com/130/how-to-write-a-custom-image-picker-like-uiimagepicker and http://mobileorchard.com/ios-advanced-programming-the-image-picker/ that might help you
I have similar code in one of my projects, but I had
[self presentViewController:imagePicker animated:YES completion:nil];
instead of
[self presentModalViewController:imagePicker animated:YES];
Try that and see if it works. Note the presentViewController rather than presentModalViewController.
Add a property in .h
#property (strong) UIPopoverController *pop;
In you r .m file under your button implimentation add something like:
if (self.pop) {
[self.pop dismissPopoverAnimated:YES];
}
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES; //if you want to edit the image
self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
//choose the direction of the arrow for the popover
[self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Make sure you have your <UIPopoverControllerDelegate> delegate set in .h
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.