Landscape orientation image picker. - ios

I'm creating an app that is landscape only, it uses an image picker control.
Looking through the site I've discovered that apple only allow portrait for this for some reason. I'm okay with it flipping to portrait for this one section, if it means the user can select a photo from the library.
Below is my code that gives an error about it being in landscape mode. How do I fix this to say it's okay to flip it to portrait. thanks
-(IBAction)takePhoto{
takePicker = [[UIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[UIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}

You don't have to use ImagePickerController in portrait mode.
Just subclass it to open in landscape mode :
#interface NonRotatingUIImagePickerController : UIImagePickerController
#end
#implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return NO;
}
#end
After that, you can use your code with that class.
-(IBAction)takePhoto {
takePicker = [[NonRotatingUIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[NonRotatingUIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}

Why present an error at all? Why not just present the image picker in portrait? People are smart enough to rotate their device. Or you could write your own landscape image picker, or use one of the several open source ones available.

Related

UIImagePickerController is dismissing on didFinishPickingMediaWithInfo

From Apple Documentation.
"This supports taking more than one picture without leaving the interface, but requires that you hide the default image picker controls".
On [self.imagePicker takePicture] the delegate didFinishPickingMediaWithInfo is being called but is still leaving the interface.
Any idea how can i prevent the controller from being dismissed?Here is my code of UIImagePickerController with custom overlay.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = NO;
CameraOverlayView *overlay = (CameraOverlayView *)[self viewWithNibName:#"CameraOverlayView" owner:self];
overlay.frame = imagePicker.cameraOverlayView.frame;
imagePicker.cameraOverlayView = overlay;
overlay.imagePicker = imagePicker;
[self presentViewController:imagePicker animated:YES completion:nil];
overlay = nil;
I have same problem but i resolved this by using these classes in my code UzysAssetsPickerController for iOS
By using this i can select multiple images without dismissing the image picker. Hope this will help.
This solved my problem.Working perfectly now.Thank You everyone.
<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property(nonatomic,strong) UIImagePickerController *imagePicker;
overlay.imagePicker = _imagePicker;
overlay.imagePicker.delegate = overlay;
// may be it will help for you.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// if you want to dismiss controll then use the following code
[picker dismissViewControllerAnimated:YES completion:^{
}];
// if you wnat to being present it comment the above dismis code
}

use UIImagePickerController in landscape mode app in iOS

is it possible to use UIImagePickerController to fetch image from gallery without making whole app in portrait mode in iOS .Thanks
Create a custom class of UIImagePickerController. Override supportedInterfaceOrientations meted
- (NSUInteger) supportedInterfaceOrientations
{
//Because your app is only landscape, your view controller for the view in your
// popover needs to support only landscape
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate{
return yes;
}
//call custom view like this
CustomImagePickerViewController *picker = [[CustomImagePickerViewController alloc] init];
picker.supportedInterfaceOrientations= UIInterfaceOrientationMaskAll;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];

UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

I am getting this error only in iOS 7 and the application crashed.
In iOS 6, I never get any error, just once of memory warning when opening the camera.
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Here is what I am doing.
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];
[self presentModalViewController:imagePicker animated:YES];
I did tried to delay the presentModalViewController, but I am still getting the same message. After few seconds (7-10), the application crashed.
This error is only present in iOS 7.
Anybody has the clue?
The problem in iOS7 has to do with transitions. It seems that if a previous transition didn't complete and you launch a new one, iOS7 messes the views, where iOS6 seems to manage it correctly.
You should initialize your Camera in your UIViewController, only after the view has Loaded and with a timeout:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//show camera...
if (!hasLoadedCamera)
[self performSelector:#selector(showcamera) withObject:nil afterDelay:0.3];
}
and here is the initialization code
- (void)showcamera {
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];
[self presentModalViewController:imagePicker animated:YES];
}
This error also showed up for me with Apple's PhotoPicker sample code project.
I was using Xcode Version 5.0 and iOS 7.0.3 on an iPhone 4.
Steps to Reproduce:
Download Apple's PhotoPicker sample project at
https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html
In APLViewController.m comment out line 125
//imagePickerController.showsCameraControls = NO;
In APLViewController.m comment out lines 130-133
//[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
// self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
// imagePickerController.cameraOverlayView = self.overlayView;
// self.overlayView = nil;
Build and launch the app.
Once launched, rotate device to Landscape mode.
Click Camera icon to open UIImagePickerController in Camera mode.
View the console output.
Console output
PhotoPicker[240:60b] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
showsCameraControls property
The problem occurs for me when this has a value of YES (the default).
Setting this to NO eliminated the message.
Bug report
I just filed a bug report with Apple.
I've tried many of the suggestions that have been made in different posts, but have not found a satisfactory workaround.
I got the problem when I tried to present the camera view inside of a popover. Under iOS6 this was no problem but in iOS7 I got the message
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
as well.
However after I changed the presentation of the camera view to fullscreen as described in Taking Pictures and Movies, iOS Developer Library everything went fine again and the message never appeared again. However I had to make sure that depending on in which mode the app is (i.e., presenting camera view or photo roll) I had to either dismiss the popover or the view controller whenever the method - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker was called.
create a property
#property (nonatomic) UIImagePickerController *imagePickerController;
Then
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
self.imagePickerController = picker;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
This should solve the problem
I used this code to workaround the problem:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[imagePicker setShowsCameraControls:NO];
[self presentViewController:imagePicker animated:YES completion:^{
[imagePicker setShowsCameraControls:YES];
}];
} else {
[imagePicker setShowsCameraControls:YES];
[self presentModalViewController:imagePicker animated:YES];
}
I have the same issue and found a solve. I think, that error related with orientation of your application. My application uses only landscape mode, but UIImagePickerController use portrait mode. I add try-catch block to main.m, and get real exception:
Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
How i solve this problem:
1) Recheck device orientation in Target->General, or .plist file: Supported interface orientations : Landscape left, Landscape right.
2) Add in AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortrait;
}
After this step UIImagePickerController works properly, but my viewcontrollers can be rotated to portrait mode. So, to solve this:
3) Create a category for UINavigationController, (supportedInterfaceOrientations moved from UIViewController to UINavigationController in iOS6):
#implementation UINavigationController (RotationIOS6)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
#end
This solution works properly on iOS 6.0, 6.1, 7.0. Hope this helps.
I get this error when building app with iOS SDK 6.1, deployment target iOS 6.1 and running app on iOS 7 powered iPhone. App doesn't crash but implementing UIViewController shouldAutorotate method helps me to remove error message.
- (BOOL)shouldAutorotate {
return YES;
}
I had the same issue when I was trying to modify the demo app that come with the Avirary SDK,
in the demo app, it can only edit the photo picked from the camera roll. To try to edit the photo by capturing from camera, I first added the following code in the UIViewcontroller.m file:
#pragma mark - Take Picture from Camera
- (void)showCamera
{
//[self launchPhotoEditorWithImage:sampleImage highResolutionImage:nil];
if ([self hasValidAPIKey]) {
UIImagePickerController * imagePicker = [UIImagePickerController new];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES]; //important, must have
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:imagePicker animated:YES completion:nil];
}else{
[self presentViewControllerInPopover:imagePicker];
}
}
}
Then when I run the app, the error occurred:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
To solve the error, modified the UIImagePicker delegate in your UIViewContooler.m file as shown below:
#pragma mark - UIImagePicker Delegate
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL * assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
void(^completion)(void) = ^(void){
[[self assetLibrary] assetForURL:assetURL resultBlock:^(ALAsset *asset) {
if (asset){
[self launchEditorWithAsset:asset];
}
} failureBlock:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enable access to your device's photos." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}];
UIImage * editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
if(editedImage){
[self launchPhotoEditorWithImage:editedImage highResolutionImage:editedImage];
}
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self dismissViewControllerAnimated:YES completion:completion];
}else{
[self dismissPopoverWithCompletion:completion];
}
}
Then the error disappeared and the app works!
Try this, use
[self performSelector:#selector(presentCameraView) withObject:nil afterDelay:1.0f];
and function
-(void)presentCameraView{
[self presentViewController:imagePicker animated:YES completion:nil];
}
to replace. [self presentModalViewController:imagePicker animated:YES];
and of cause make imagePicker as a global variable.
This is what fixed it for me on my app, ymmv
first off it is a iPhone - iPad app
in appname-Info.plist. in the Supported interface orientations(iPad) showed 4 orientations.
in the Supported interface orientations showed 3 orientations. I added the fourth and ran the app, no debug output.
Hope this helps.
I've just encountered the same issue. In my case the problem was that I had some non-ARC code and I've migrated it to ARC. When I did the migration, I didn't hold a strong reference to the UIImagePickerController and that was the reason for the crash.
Hope it helps :)
I had same issue in iOS 8, But the Camera Access was Disable inside Settings--> Privacy for my App. Just Enabled it, and It was working.
I spent long time try to find the solution, and surprisingly I have found it at the end and it was just very funny once I discovered it.
Here is what you will do to retrieve the image you picked and resume working :)
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImage* pickedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[composeImageView setImage:pickedImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
Yes, to solve the issue, you only need to dismiss the picker normally as it seems this message: "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates." stops the picker from being responsive but you can dismiss it and retrieve the image normally.
In my case it was related with a layout change: the VC presenting the UIImagePickerViewController has the status bar hidden, but the UIImagePickerViewController hasn't.
So, I solved it hiding the status bar in the UIImagePickerViewController as it's shown in this answer.
Not directly answering your question but you mentioned you had a memory warning ,you might be storing the raw image in a property which can lead to a memory warning. This is because the raw image takes up roughly 30MB of memory. I noticed a similar memory warning when testing apps on iOS6 which were on the iPhone 4 series. I still got this warning when the devices were upgraded to iOS7. There is no memory warning when testing on iPhone 5 series on iOS7.
Changing
[self presentViewController:imagePicker animated:YES completion:nil];
to
[self presentViewController:imagePicker animated:YES completion:NULL];
fixed the issue for me.

How to make only MPMoviePlayerController in both landscape and portrait mode

I am working on a application which has to play videos when clicking on some thumbnail, I am displaying list. I want only the Video to rotate in Landscape and Portrait Mode but other screens must in Portrait Mode How can we do this.
In ViewWillAppear
UIViewController *vc = [[UIViewController alloc] init];
[self presentViewController:vc animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
This will trigger the redrawing of the view and thus calling following functions, provided you have implemented these
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

How do I implement a UIImagePickerController with a TabBarController

I have been beating my head on this for a few hours. I have some sample code (using a UINavigationController) when the view loads the camera roll will be presented. However, when I try to incorporate the same code into my app, which has a tabBarController, I get a blank modal UIImagePickerController. I didn't track down what I am doing wrong.
// bring up image picker
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
NSLog(#"UIImagePickerControllerSourceTypePhotoLibrary available");
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
ipc.allowsEditing = YES;
[self.tabBarController presentModalViewController:ipc animated:YES];
[ipc release];
}
Any insight would be appreciated.
Not sure what has changed, but this is possible by calling presentViewController from your tabBarController. This is the standard now and ensures your camera or image picker always gets presented as a full screen modal view.
For reference: presentViewController

Resources