ios6 Rotation issue from landscape to portrait mode - iphone

I am using New orientation methods of ios 6 and it is working fine. My view is presenting in portrait mode and when I presentviewcotrnoller and rotate it to landscape , dismiss that viewcontroller it reverts orientations. means it should remain in landscape but it becomes to portrait.
Here is my code.
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
I think it is happening because of preferredInterfaceOrientationForPresentation method ,but not getting the solution for this.Please Help !
Thanks !!

If you want all the interfaceOrientations supported at the start, do not write the preferredInterfaceOrientationForPresentation method, as it would take just that preferred Interface orientation all the time.

Related

Screen rotation on a per view basis

With iOS7, even though the app has the Device Orientation under General set to landscape and portrait. There are some screens in my app that I do NOT want to be able to rotate.
How can you pick and choose which views get rotated when the device turns?
I tried to use shouldAutorotateToInterfaceOrientation but I could not get it to work.
Anyone accomplished this with the new software?
try the following code in the views that you want it to be just landscape and change the landscape part to portrait in the views that you want it to be only portrait.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
Try overriding - (BOOL)shouldAutorotate and return NO.

iOS 5.0 Modal View Not Rotating(Story Boards)

I use story boards. In every view controler I want to rotate I included this method like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
in iOS 6 it rotates just fine to the proper views I have for landscape and portrait in my story boards.
in iOS 5 the parent view contoller rotates but the modals don't rotate while they are on the screen, they only rotate before they are on the screen but never during. So when a user changes orientation it remains the same. A parent will change while on screen but the modal will take on the orientation the parent had but will not change while on screen. How do I get my modal views to work like iOS 6 where they will rotate when on the screen. The modal view were created via the storyboard.
Edit*
When I do a popover to a modal, the modal doesn't rotate. How can I fix this?
Rotation is handled differently in iOS5 and iOS6. I use the below code to support both versions.
// iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// iOS6
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate
{
return YES;
}
shouldAutorotateToInterfaceOrientation: is deprecated in iOS6. You can read here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:

Unable to lock screen orientation to portrait only in xcode 4?

In xcode 4 I am unable to lock the screen orientation to only portrait even though I have portrait selected only. How to I do this programmatically?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
this code works in a new blank project
The accepted answer did not work for me either. This did:
In the properties file for your app (YOURAPPNAME-Info.plist), located in the "supporting files" group, there is an array called "Supported interface orientations". Remove both landscape values from the array and your app will be locked in portrait orientation.
For each view controller (or just the parent), implement -shouldAutorotateToInterfaceOrientation: Set the default orientation to portrait and then do:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
Alternately, you can do:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
which will allow a rotation to portrait but not away from it.

shouldAutorotateToInterfaceOrientation with iPad and iPhone differences

I have an iPhone app which I have created as a universal iPad/iPhone app. I've implemented a splitviewcontroller for the iPad version... all fine.
In my iPhone app, everything is in Portrait, except for a 2nd level view controller (a web view), which I override shouldAutorotateToInterfaceOrientation to allow landscape. On returning up the view chain I go back to portrait.. Excellent!
However, Now my iPad split view app is forced to stay in portrait. If I override shouldAutorotateToInterfaceOrientation in any of my views like rootviewcontroller or others it effectively allows landscape mode in my iPhone app which I cannot do. However it does fix my landscape problem in the iPad.
Is there a way round this? I effectively want to say YES to shouldAutorotateToInterfaceOrientation for iPad, but no for iPhone. I tried this, but it doesnt work, it allows landscape on both devices:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
BOOL rotate = NO;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
rotate = YES;
}
return rotate;
}
Any advice?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

Tabbar Nav app, allowing one view to rotate while others do not

I have a tab bar application in which i have 3 diffrent views each with there own view controller.
In the tab bar code i have this, to handle rotation.
#import "RotatingTabBarController.h"
#implementation RotatingTabBarController
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
#end
Then in the 2nd view controller that i want to rotate depending on device orientation i have:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
And For the other two views that i do not want to rotate i have this method set.
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
The PROBLEM: so this works fine in view 1 and view 3 when u rotate the device they stay in portrait mode which is desired. When in view 2 i rotate to landscape, the view does as expected and rotates to landscape. BUT when click view 1 or view 3 tab while in lanscape mode in view 2, View 1 and View 3 are in landscape mode.
I can't figure out how to force them in portrait even if view 2 rotates to lanscape.
Any one know how to do this?
There's a big discussion[1] on this dating back from 2008 until now (look at comments down a few pages) -- summarily it seems like
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
or
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
or
[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
will let you force it to landscape -- you would want to do this when the user goes back to your landscapey view(s) programmatically.
[1] iPhone app in landscape mode, 2008 systems