Autorotation in iOS 6 & iOS 7 - ios

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

Related

ios7 interface orientation - restrict orientation to particular viewcontroller

I have two UIViewControllers in my UINavigationController stack, in which i need to support portrait and landscape orientations for the first viewController alone and for the second viewController, i need portrait support alone and not landscape.
In ViewController1, I have implemented the following methods,
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self changeFrames:toInterfaceOrientation]; //changing frames for orientation accordingly
}
and in ViewController2:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Also in project target, i have set to support all the 4 orientations.
Looking for any kind of help to solve the above issue.
Thanks in Advance.

What are the methods for Orientation in iOS 7?

In my Application one of the ViewController is need to be supported from portrait to landscape/landscape to portrait, and remains support to portrait only I achieved this in Xcode 4.6 with iOS 6 but when I run my code in Xcode 5 with iOS 7 those methods are not being called. Is there any methods deprecated in iOS 7. If yes what are those methods?
I have created a sub class for UINavigationController and below is the my code which is working fine in iOS 6.
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
// return [[self.viewControllers lastObject] supportedInterfaceOrientations];
return [[self topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject]
preferredInterfaceOrientationForPresentation];
}
Please help me. Thanks in advance.
Have you checked this mark these all device orientations
oky, in the viewcontroller that needs to support landscape use the following code
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationLandscapeLeft; //which side u want weather left or rite
}
and view controllers that supports portrite
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
you hav to set the supported orientations as #Gurpreet said ..
try this, hope this helps u :)

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

iPad Orientation Not working as it should

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

Rotation isn't working in iOS5 Storyboard

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:

Resources