Rotation isn't working in iOS5 Storyboard - ios

I'm working on a storyboard app and the rotation works on iOS6 devices but when I run it on my iOS5 device it won't rotate. I have a View Controller embedded in a Navigation Controller (so the Navigation Controller is the root view controller of the window) and I have the following methods overridden:
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation ==UIInterfaceOrientationPortrait)){
return YES;
} else {
return NO;
}
}
I also have the 3 orientations allowed in my plist, and my deployment target is iOS5 with the base SDK iOS6 and autolayout is turned off, and ideas why this isnt working?
Thank you!

Your comment caused me to look closer. It's because you have a capital 'R' in autorotation.
Change your method name to:
shouldAutorotateToInterfaceOrientation:

Related

Storyboard ignores UIInterfaceOrientation settings

I have a strange problem with UIInterfaceOrientation. In my project there are many different views, some of them should rotate in landscape mode, and some of them should not. The problem is that all the view which were not created using Storyboard and in which only the UIInterfaceOrientation portrait is enabled this works fine and the view does not rotate, instead all the views created using the Storyboard, even if the UIInterfaceOrientation landscape mode was disabled they keep rotating. In my Xcode project setting those checks are enabled and I cannot change them:
How can I completely disable the device rotation in all the different views? [Storyboard or not].
This is the code I use to disable the device orientation in all the storyboard view controller, but it does not work:
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Try this code maybe it will work for you.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientationMask)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationMaskPortrait);
}
The solution was to assign a UINavigationController class to the UINavigationController in the Storyboard file and to place this code in his .m file:
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Please, check if in your project .plist there are more than one item for orientation or something strange. I sometimes have found that orientation has different values in plist or duplicated keys.
Hope it helps

Autorotation in iOS 6 & iOS 7

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

iOS - Force Landscape Orientation

I've been trying to figure this out for a while now and its possibly a duplicate but I haven't found a correct solution. So I've created a view controller and the build the xib in landscape mode. When I try to push the view controller, it displays as Portrait but I want it to show up landscape. I've added the following methods to my code:
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Any help is appreciated!

Locking the Landscape Mode in iPad

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;
}

Stop UIView from roating into landscape

I have a UIView thats inside a navigation controller, I am trying to prevent this view from going into Landscape however the method I am trying to use never fires.. code is below any help would be greatly appreciated..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return NO;
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
return NO;
}
return NO;
}
You should set return NO; for the parent navigation controller or on a UIViewController, not a UIView.
Also, this works just the same with less code:
iOS 5.x
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
iOS 6
As of iOS 6, shouldAutorotateToInterfaceOrientation: is deprecated. If the view controller does not override the supportedInterfaceOrientations method, UIKit obtains the default rotations from the app delegate or the app’s Info.plist file.
You will need to use:
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
Another option is modifying Deployment Info.
This method needs to be implemented in a UIViewController instance, not a UIView.
Also, you are in fact returning NO for all orientations, which is incorrect. You need to return YES for at least one orientation (most commonly UIInterfaceOrientationPortrait).

Resources