Disable Landscape Orientation in IOS5 - iphone

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

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.

iOS Enable Rotation for all Orientations iOS 5

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

having issue with shouldAutorotateToInterfaceOrientation

I have the following code in my UIViewController and I am testing for iOS 5 in a device and both simultor.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (IS_IPHONE){
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
} else {
return YES;
}
}
I put a breakpoint and it is indeed getting called, however it still rotates to landscape. Why is this?
Because you told it to do so. return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown; means that you want to autorotate to every direction except portrait upside-down, and that includes landscape. For iPad, even this constraint is missing, so it will autrotate to any orientation.
(You should have a fresh breath of documentation...)
Use this instead
return (interfaceOrientation == UIInterfaceOrientationPortrait);

convert iphone to ipad but screen do not auto rotate while rotate the ipad

I convert my tabbar based iphone app to ipad version with different ~ipad.xib, the only different is the ui element size. Now my question is that it can't auto rotate the screen in ipad version, i.e. I upsidedown the ipad, but the ui don't rotate upsidedown.
You need to return YES for the shouldAutorotateToInterfaceOrientation: for all view controllers featured in your tab bar, for iPad only (UI_INTERFACE_IDIOM()...). The default code from your iPhone controllers probably only returns YES if it is portrait, if that is all you selected when initially creating the project.
Here is the code I use for this situation (iPhone, portrait only, iPad, all orientations):
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return YES;
else
return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
Tab bar controller can not auto rotate. you have to rotate all the component.
You can use this code to accomplish your task in case of universal apps
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
BOOL ret;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
// iPad-specific code
if (interfaceOrientation != UIInterfaceOrientationPortrait) {
ret = YES;
}else{
ret = NO;
}
} else {
// iPhone-specific code
ret = YES;
}
return ret;
}
You need to modify 'Supported Device Orientations' to include your new orientations

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 :)