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.
Related
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:
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.
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.
I have a navigation controller and it goes through that in portrait. Then, at a certain point, I push to a view that displays a graph, which I want to only display in landscape, and not even be in portrait at all (this screws up how the view looks).
In this view, GraphViewController, I have the following method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
When the view first gets pushed, it appears in portrait mode. If I rotate the phone, the view will rotate into landscape also (not upside down portrait). But I want it to not even ever be in portrait mode, not even when it starts. I have verified that this method is getting called by adding a NSLog.
I saw these posts but could not get it to work. Thanks!!
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
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);
}