I have released an app, and for some reason only some people are having an orientation issue with the app. Namely that it is opening in Portrait mode, and is un-rotatable from here where as the app is set up to only be allowed in LandscapeLeft and LandscapeRight. Most people aren't having this issue, however I've received a few complaints recently through our support page.
People with the issue seem to be on iOs 5.1 and iPad gen 1s, which is the lowest OS my app supports.
Here is the code handling the rotation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}
And here is the .plist
http://tinypic.com/r/nnvfhz/6
Any suggestions would be great.
In iOS5, you must override the shouldAutorotateToInterfaceOrientation: method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// support all interface orientations
return YES;
}
This method was deprecated as of iOS 6, for which you should use these:
- (BOOL)shouldAutorotate {
// return whether autorotation is supported
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations {
// return the mask that represents the supported interface orientations
return UIInterfaceOrientationMaskAll;
}
Finally, I'll mention this method, since it's often applicable:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
// set the preferred orientation of view controllers presented in full-screen
return UIInterfaceOrientationLandscapeRight;
}
Related
i am working on a app where I am required to show "MPMoviePlayerController" in landscape mode and portrait mode. But My whole app is required to support Portrait mode only. That is no landscape mode for any view other than for the "MPMoviePlayerController".
I tried few things given over stack overflow. Nothing worked in my case. Feels Stuck in the middle. But I have seen some of the app supporting suck kind of requirements.
I have to implement it for both iOS 6, 7
In my app am using "XCDYouTubeVideoPlayerViewController" for playing videos(playing the youtube videos)
Please Help
I had the same issue, and the following solved the problem:
First you need to allow the Landscape mode either, by checking the checkboxes at Target / General / Deployment Info / Device orientation, and then you have to disable Landscape orientation by code at every ViewController you use in your app.
#pragma mark - Set Supported Device Orientation
//For iOS6
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
//For iOS4 and iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But don't disable landscape orientation for the XCYoutubeVideoPlayerViewController, so at fullscreen it can rotate to landscape.
I have another solution for this, It will work for all MPMoviePlayerController, below is my code
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
[[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(#"MPInlineVideoFullscreenViewController")])
{
if ([self.window.rootViewController presentedViewController].isBeingDismissed)
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
What we basically do here is we enable Landscape orientation for all MPMoviePlayerController classes which are actually MPInlineVideoFullscreenViewController when you present it for fullscreen.
Hope this helps
I want to support the autorotation in iOS 6 and 7. In my project I have a UITabBar with 4 ViewControllers. Only one ViewController of them should support the autorotaion to Portrait and Landscape. The other views should support only the Portrait style.
I hope you have an idea how to implement this function. shouldautorotatetointerfaceorientation doesn't work in iOS 7 :(
I added a UITabBarConntroller to control the autorotation
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.selectedIndex == 1)
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationPortrait);
else
return UIInterfaceOrientationMaskPortrait;
}
Maybe there is a way to change the Orientation manual when the View with the index 1 did disappear??
I hope you have a solution!
Set the orientations settings like this:
In UITabBarController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
Open project
Go to the General tab
Under orientation options check all checkbox orientation that you need to support
Go to the implementation of first view controller and add this code:
- (BOOL)shouldAutorotate
{
return YES;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAll);
}
Go to all other view controllers that are represented your tabs and set:
- (BOOL)shouldAutorotate
{
return NO;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Check this link as well
My app launches in Portraits mode correctly and works great , But in my Application Some Views Support Landscape mode only and some Both landscape and Portraits, when i Switch the application view from Only Landscape Supported to some view that support both orientation and rotate the Device to Portraits and Hit The Back Button , the Landscape view is not rotated Automatically
i use the following code to set the orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
Thanks
Edit these lines
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
As
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (toInterfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft) {
return YES;
}
else {
return NO;
}
}
I have an application on AppStore that has portrait Mode on iPhone and on iPad it works on landscape. However i am getting reports that it shows portrait on iPad 1 thus destroyed overall View.
Why is iPad 1 specifically showing Portrait mode?
The version of iPad is 5.1.1
In ios 6, the methods for supporting interface orientation has been changed. For supporting both interface orientation in both version, we need to check the os version and write code acoordingly.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Support for new versions
- (NSUInteger)supportedInterfaceOrientations {
}
- (BOOL)shouldAutorotate {
}
In my View Controller i have the following:
- (NSUInteger)supportedInterfaceOrientations {
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}
- (BOOL)shouldAutorotate {
}
Go and make sure ALL view controllers return the correct orientation modes they support. I've seen such behaviour in iOS 5 and if I recall correctly that was the reason.
I had a very similar from and I resolved it by changing the following code in AppDelegate.m-> applicationDidFinishLaunching:
[self.window addSubview:self.viewController];
to
[self.window setRootViewController:self.viewController];
I am using this code to lock the landscape mode for my iOS application.
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
It is working fine in iPhone but it is not working correctly in iPad. It does not lock the landscape mode.
Need some guidance on this.
This code is incorrect:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
A UIInterfaceOrientation is not a UIInterfaceOrientationMask. Try something like this instead:
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
That being said, if you are trying to lock your application into landscape mode, there are multiple other issues here — for instance, your supportedInterfaceOrientations lists only portrait modes, not landscape!
Ideally just set it in the summary tab as the comment says. If you really want to do this in code, this is only available in whatever you set as the rootViewController in your AppDelegate class.
In iOS 6 I use:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
If you have a NavigationController you can add the method to a Category.
I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}