iOS Enable Rotation for all Orientations iOS 5 - iphone

I've written a tabbed application with a few view controllers, and on iOS 6 it rotates happily in all orientations as I've got them all supported in the app summary.
My deployment target however is iOS 5 and I'd like to be able to rotate in all orientations on this too. I've tried varies combinations of:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscape;
}
But none are enabling rotation for iOS 5. Do I need to put this method in just the app delegate or in all the view controllers? Am I doing it totally wrong??
Cheers,
Chris

You can add this all your view controllers
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscape);
}
or you can edit your plist's Supported Interface orientations

for iOS 5.0, also add to your view controller, and you can also change it in your build settings, and your info plist file, to be sure.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

Using:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationPortraitUpsideDown;
}
Worked great

Related

iOS 6.0 orientation problems in universal application

I have an app that has a UIViewController as the root view controller (not a TabBar or NavigationController app!). This app is universal. It should always be portrait for iPhone and always be landscape for iPad.
I've tried the following, but I think this is iOS 5 code because it's not being called in iOS 6:
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
else
{
return (interfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight));
}
}
Any help is appreciated!
Here is the set of code for iOS 6. It uses masks. If it is for the entire iPhone one orientation and iPad one direction, then at the project level you can set that up by deselection the buttons related to the orientations you don't want. That is if all the views in iPhone are going to be the same, and for iPad it's also applicable. If you want to do it with codes, the the following will do the job:
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Just take the orientations you don't want to use out. Let me know if you need more help please.

orientation methods on iOS 6 [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ios 6 orientation methods
the orientation methods have changed in iOS 6. my whole app in portrait mode got to many view controllers (not tab bar view controllers) i just want to rotate one of my view controller to landscape mode (it actually displays a webView) when i rotate the device.the below method was working in xcode 4.4 but, it's not in Xcode.4.5
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight );
the above method won't work in xcode 4.5 for this reason i have changed the below method but even though its not working....plz any suggestions thanks.
- (BOOL) shouldAutorotate{
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
return self.modalViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
are you implementing supportedInterfaceOrientations as well ? you might want to.

Disable Landscape Orientation in IOS5

I want to eliminate Landscape Orientation in my application, which is built for IOS 5. In IOS 6 I know this is possible - but it doesn't seem to be working for me in the earlier version.
I am setting only two orientations in my plist file (Portrait w/Home Button on Top and Portrait w/Home Button on Bottom). Regardless, Landscape still crops up in IOS 5.
Is there something further I need to do to eliminate this from happening?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return NO;
}
else
{
return YES;
}
}
write this code in .m file for ios5 orientation
let me know it is working or not....
Happy Coding!!!!
This will work. Go to storyboard deselect the orientation you don't want and in view controller, write this code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}

rotate window based iphone app

I am working on window based iPhone app.
I wanted to add rotation feature by using,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
but it does not work.
What is wrong with this.
Note: xCode 4 , iOS 4.3
Regards.
In Xcode 4 click on the project the very top item in the left bar and then click on the summary tab and make sure the supported orientations is set correctly.
If that is fine then you might try rewriting the return line to be something like this:
return(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
If that doesn't work just try return YES; and see if the views will rotate.

Remove ability for portrait orientation for app in iPhone SDK

Is there a way where I can only allow my app viewable in landscape mode? I've managed to default the application's orientation to landscape, however in the iPad simulator, when I do Command->Arrow, the application rotates to portrait. I've removed the listings in the plist under "Supported interface orientations" for both of the Portrait entries, however that doesn't seem to've changed anything.
Any idea?
In your view controller, there's a delegate method for this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Do a project find for "autorotate", and edit the methods you'll find accordingly.
I believe you need tell the view that the specified orientation is not supported
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:
Actually it is
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Things have changed with some updates. Currently, you'll simply need to add the following method:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
that will only allow landscape. Turn the phone all you like and it will only stay in either left or right landscape. Have fun :)