Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force landscape orientation in UIImagePickerController

I'm new to iOS development, and Im developing my first app. (so sorry if Im asking a newbie question)

My app is all in portrait orientation, except to the place where I'm using UIImagePickerController to take a picture to be used in the app, what I'm doing is:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];

As my app is in Portrait, I need to make something to the UIImagePickerController be in landscape only. if I try to use:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

It seems that I can't use, because my Xcode identify as a error in this lines (probably because of Xcode the version, I'm not sure). And I'm not sure, but it seems that if I'm developing for iOS 5.1 I will need to implement something for iOS 6.0 too, is it correct?

Can someone help me to understand what is need to make this UIImagePickerController, and only this view controller in the app, work in Landscape orientation and works in iOS 5.1 and 6?

Regards

like image 407
Fernando Avatar asked Jan 31 '13 04:01

Fernando


People also ask

How do I implement the uiimagepickercontroller?

The UIImagePickerController is a view controller that gets presented modally. When we select or cancel the picker, it runs the delegate, where we handle the case and dismiss the modal. Let’s implement the photo library first, then the delegates. Add the following code to the photoFromLibrary method:

How to detect orientation of the user on orientation change?

Detect the orientation of the user on orientation change. [Method is already in the first part.] If the orientation is landscape and user should be in portrait mode for better experience. Show the user such message in place of locking it. (Reason: Screen lock is not supported in Safari on iPhone).

Is it possible to force the user to lock screen orientation?

It is not recommended to force the user to lock screen in one screen orientation. But locking screen orientation is a necessity in some cases like - gaming, video contents, PDF contents. Using pure JavaScript API designed for modern browsers. Using complete CSS code. giving user a message to use in portrait mode.

How to put a photo in UIImageView in Xcode 8?

Xcode 8 come with a series of easily accessible preview modes in interface builder. We will put a photo into an UIImageView when we first use the image, and doing so on an iPad is easier than an iPhone, though it will work on both. Right-click and save the image below: Click on Assets.Xcassets and drag the pizza file into the assets folder.


1 Answers

As per the UIImagePickerController Class Reference

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

So it looks like forcing landscape mode is unsupported and discouraged, unless you do so by replacing the default controls with a custom cameraOverlayView.

like image 110
Glenn Barnett Avatar answered Sep 22 '22 05:09

Glenn Barnett