iPad 2 UIImagePickerController camera auto-rotation driving me mad! - ipad

I've been trying to sort this one out for a while and getting nowhere.
I'm using the camera on the iPad 2 - my application is in landscape, but I want to use the camera in portrait mode. I just can't seem to force the ImagePicker a, into Portrait mode, and b, to stop auto-rotating.
Is there any way that you can force the ImagePicker into portrait (or landscape), and/or to stop it auto-rotating?
Even though the App is in landscape and is set to return YES only to landscape orientations, the ImagePicker ignores that and rotates into portrait when you rotate the iPad 2.
If I could force it into staying in landscape then (although not ideal) I could re-design the app to use the camera in landscape, but I don't seem to be able to do even that!
Any help greatly appreciated!

The method that you need to override called:
_isSupportedInterfaceOrientation:
So it should look something like this :
#interface PortraitImagePickerController : UIImagePickerController {
}
#end
#implementation PortraitImagePickerController
- (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation{
return UIDeviceOrientationIsPortrait(orientation);
}
#end
But it's definitely private method so Apple may reject your app

Well i have found a more convenient way and has no risk of using private code.
Sub class a UIImagePickerController and add following method in its .m file.
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

Related

Not able to have all orientation for iPad

Hi guys i know this question might be asked before as well , so if u could point out right question to refer to that would be great .
Problem - in my info.plist i have only 2 orientation allowed i.e Portrait ,UpsideDown
and every viewController abides to above orientation .
But for one particular viewController i want whole 360 degree orientation .
this viewController is presented modally with style
UIModelPresentationStyle.FullScreen
And to support all orientation in ViewController ,
i have overridden relevant delegate methods as well
ShouldAutorotate is returning -> Yes ,
PreferredOrientationForPresentation is returning -> UIInterfaceOrientation.LandscapeLeft ;
GetSupportedInterfaceOrientation is returning -> UIINterfaceOrientationMask.all
When this ViewController loads i am getting landscapeLeft as expected , when i rotate the iPad, i get portrait mode as well ,
but now i am not able to return back to landscape mode anymore .
Any reason for that???
in my info.plist i have only 2 orientation allowed
Well, that's the problem. You're doing this wrong. The Info.plist should list every orientation that the app can ever have. Your top-level view controllers can then limit their own orientations.

How to create a landscape-view only ios application

I want to create an iOS app that can only work on landscape-view mode.
I Googled how to do that, and end up with supportedInterfaceOrientations method
Here's my attempt:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
I tried to put the above code on viewController.m and AppDelegate.m, but it didn't seem to work
Thanks, any opinion will be much appreciated
You don't need to write any code to run app which supports landscape mode only. Just select app target and uncheck portrait and portrait upside down orientation and make sure landscape orientation is checked.
It seems as though you want to programmatically change the orientation of your application. This can be done by any ViewController by implementing one method.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
That should force the view to auto-rotate in the direction you want it.
When you use -supportedInterfaceOrientationForPresentation it simply states that the returned interfaces can be used, not necessarily that they should be used.
When you use -preferredInterfaceOrientationForPresentation it says that this is orientation that I want, and that the ViewController should switch to it.

Is it possible to force orientation in IOS

Is it possible to have a portrait app that contains several different screens, however when the camera in the app is activated it switches to Landscape view and after the camera is done taking the picture returns back to portrait ?
(I want to force the user to only take landscape pictures).
if you read the https://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
you'll find out that the uiimagepickercontroller only supports portrait. here is the part from the 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.
the only way would be to create a custom camera overlay method and do it in that method.
if u using some landscape gradient picture for hide the user to take picture in only landscape

GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation

Problem:
If user is not logged into GameCenter account - GameCenter authentication view is launched in portrait mode (in ios 5 there were a modal dialog) asking to log in. But if I disable Portrait mode in xcode (Project Summary) or in supportedInterfaceOrientationsForWindow: (as my app supposed to run in landscape mode ONLY) I get:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
If I enable Portrait for ipad/iphone (and/or comment out supportedInterfaceOrientationsForWindow:) it works without crash, but I don't want portrait mode to be enabled.
While writing this question and experimenting with code, it seems that I've found a solution:
enable all orientations in project summary and remove application:supportedInterfaceOrientationsForWindow.
Add this code to ViewController:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Now it works seamlessly.
Add to app delegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);
}
I have found that the problem is coming from the Game Center in my case. When in the simulator I do not have the Game Center initialized yet, it would like to pop up the login view, but in portrait mode. Once it is reaching this point it crashes if I disallowed portrait orientation. Strange bug in the OS as Game Center should take the allowed orientations only to be inline with our intention of landscape user interface.
I do not have the solution yet, but I will post if I find it.
I had the same issue as you and I fixed it with a kinda, ugly work around, basically I have a global variable in my app that I use to choose what the valid interface orientations are. In the
- (NSInteger)application : (UIApplication *)supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(orientationIndicator == 1){
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else if(orientationIndicator == 2){
return UIInterfaceOrientationMaskLandscape;
}
}
To declare the global variable put this in your appDelegate.m file :
int orientationIndicator = 1;
To import the global variable use :
extern int orientationIndicator;
Then you can change the value of orientation indicator and it will allow you to run in different interface types. So what I did was I start by making the orientationIndicator = 1. When you authenticate a player and initiate the login view controller set the orientation indicator to 2. When you dismiss the view (authenticate the player) then you can change it back to 1.
This is a slimy work around but it has worked for me.
Hope this helps!
Catching the exception appears to work just fine for me:
#try {
[rootNavigationController pushViewController:viewController animated:YES];
}
#catch (NSException *exception) {
//somehow, catching this exception just allows the view controller to be shown?
}
In iOS 6.0, the exception is thrown, but if you catch it then the viewController will still be shown and GameCenter will behave as expected in landscape orientation.
An alternate solution is just to target iOS 6.1 and above, as Apple fixed the bug by that release.

IOS4 UISplitViewController in Portrait Orientation with RootViewController showing like Landscape

In IOS 3.2 I was able to display my UISplitViewController side by side like in landscape mode.
In IOS 4.2 the RootViewController (MasterView) is not showing up in portrait mode. Does anyone know if we need to display the rootviewcontroll in a popover? Can we display it side by side like how it is in landscape mode?
I want to avoid having to click on a button to show the masterview (when in portrait mode)
In that case, you can skip the splitviewcontroller and create only view base application where you could manually control the UI.
on viewDidAppear you can do
[splitViewController setHidesMasterViewInPortrait:NO];
It works even though you get a warning. I think you can create category with a custom splitviewcontroller to get rid of the warning.
2.Otherwise you can do something like
on the viewWillAppear, you can do something like
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
UIViewController *master = [[splitViewController.viewControllers objectAtIndex:0];
UIViewController *detail = [[splitViewController.viewControllers objectAtIndex:1];
[splitViewController setupPortraitMode:master detail:detail];
}
(setupPortraitMode ) http://intensedebate.com/profiles/fgrios.
I used setHidesMasterViewInPortrait:NO and it did work on the pre-5.0 releases, and even got into the apple store once. But the next time I updated the app, they rejected it because I used a hidden API. I am still searching for a way to make this work.

Resources