I used a very popular code to capture photo with iPad
-(void)presentImagePicker:(UIImagePickerControllerSourceType)source sender:(UIButton *)sender
{
if (!self.popOver && [UIImagePickerController isSourceTypeAvailable:source])
{
NSArray *availableMedia = [UIImagePickerController availableMediaTypesForSourceType:source];
if ([availableMedia containsObject:(NSString*)kUTTypeImage])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = source;
picker.mediaTypes = #[(NSString*)kUTTypeImage];
picker.allowsEditing = YES;
if (source != UIImagePickerControllerSourceTypeCamera &&
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
self.popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
[self.popOver presentPopoverFromRect:sender.bounds
inView:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
self.popOver.delegate = self;
}
else
{
[self presentViewController:picker animated:YES completion:nil];
}
}
}
}
The problem is that when the picker shows up, the cropping-size of the capture image is different from the size of the iPad (full screen). It is like a box centered in the screen.
When I take the picture in portrait mode, the captured image is not the portrait image, but something different in size.
My application can run only in landscape mode: is that the problem?
The solution is here
GKImage picker
a custom picker, very very useful.
Related
It's an iPhone app running in iPad in iOS7. In iPhone it works fine.
However in iPad, the rotate button is not displayed and the view is like cut off on the top.
I'm not doing anything strange with the image picker. Here's how I show it:
- (void)showImagePickerWithSourceType:(UIImagePickerControllerSourceType)sourceType
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.mediaTypes = #[(NSString*)kUTTypeImage];
imagePicker.sourceType = sourceType;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
//Select front facing camera if available
if (sourceType == UIImagePickerControllerSourceTypeCamera && [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
[self presentViewController:imagePicker animated:YES completion:nil];
}
I have an iPad app in which when I click on the button it opens a popover with the iPad library to see the photos and pics. I want that when I click the button it should also show video in that but it does not show videos.
In device when I see library it shows videos but when popover opens in app it does not show any video.
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
}
else {
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
First Create normal popover then add this code to for button 'choose photo from gallery'
UIImagePickerController *imagePicker1 = [[UIImagePickerController alloc] init];
imagePicker1.contentSizeForViewInPopover=CGSizeMake(300, 200);
imagePicker1.delegate = self;
imagePicker1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
Popcontroller = [[UIPopoverController alloc] initWithContentViewController:imagePicker1];
[Popcontroller presentPopoverFromRect:cell1.ButtonAddPicture.frame
inView:cell1.ButtonAddPicture.superview
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
and for video add following line to above code
imagePicker1.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
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:
I am developing an iPad app to take a photo or choose from library.
It works fine, the only problem is the camera layout incorrectly when you follow the steps below.
List item
Tap btnPhotoLibrary button
Cancel the popover
Tap btnCamera button
The resulting layout is very similar to the image in
Camera has incorrect screen placement when open fullscreen modal from popover.
It is positioned slightly lower than the screen bounds. This means
that the controls at the bottom are 20px south of the screen and there
is a 20px black band at the top of the screen
You have no problem if you do not tap btnPhotoLibrary but btnCamera only.
We are using the same UIImagePickerController instance for both of camera and photolibrary, so we probably need to reset some properties before using it as a camera, but could not find a way.
--
- (void)viewDidLoad {
[super viewDidLoad];
_imagePicker = [[UIImagePickerController alloc]init];
_imagePicker.allowsEditing = FALSE;
_imagePicker.delegate = self;
}
-(IBAction)btnCamera:(id)sender{
if ([popover isPopoverVisible]) {
[popover dismissPopoverAnimated:YES];
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:_imagePicker animated:YES completion:nil];
}
}
-(IBAction)btnPhotoLibrary:(id)sender{
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([popover isPopoverVisible]) {
[popover dismissPopoverAnimated:YES];
}
popover = [[UIPopoverController alloc] initWithContentViewController:_imagePicker];
[popover presentPopoverFromRect:btnCameraRoll.bounds inView:btnPhotoLibrary permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
The target os is iOS6.1, landscape view.
Thanks in advance.
It seems that resetting view property of UIImagePickerController to nil does the trick, but I guess it's almost identical to creating a new instance of UIImagePickerController every time you need.
-(IBAction)btnCamera:(id)sender{
if ([popover isPopoverVisible]) {
[popover dismissPopoverAnimated:YES];
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_imagePicker.view = nil;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:_imagePicker animated:YES completion:nil];
}
}
I am using UIImagePickerviewController to open the photo library through the below attached code... after called bit lines of code. The application was crashed... Its working fine in ios5
UIImagePickerController* content = [[UIImagePickerController alloc] init];
content.delegate = self;
content.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:content animated:YES];
[content release];
Is anything wrong with this code?
Check Crash on presenting UIImagePickerController under ios6 You will get everything you need to make UIImagePickerviewController working on iOS 6.0.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:cameraButton.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else{
[self presentModalViewController:imagePicker animated:YES];
}
I had the same issue. Because the UIImagePicker shows on portrait mode.
I fixed it by subclassing the UIImagePicker and implementing the shouldAutorotate method like:
- (BOOL)shouldAutorotate
{
return NO;
}
I have created instance of my subclassed imagePicker instead of UIImagePicker, everything worked fine. Hope this will help you.