Reputation: 4101
I have an app written in an older version of Xcode. Right now I'm using Xcode 4.6.1. This is an app I inherited from another developer that was developed outside the company.
One of the problems with this app is its interface. It should default to LandscapeLeft (this is the value set in the pList file). The app ignores this directive and instead defaults to portrait mode.
Is there something I need to do to force the code to honor this value? I'm relatively new to iOS/Objective-C. The code compiles and runs, it's just the interface isn't doing what I want.
It's a little easier since this is an iPad only app.
Edit I've tried adding the following code to one of my problematic viewControllers, but it's not being honored. Any thoughts on how to force this view to landscape? (Is there a setting in the IDE - it looks like Xcode used to have an orientation attribute, but I can't find it in 4.6.1)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return ((interfaceOrientation==UIInterfaceOrientationMaskLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationMaskLandscapeRight));
}
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (NSInteger) supportedInterfaceOrientationsForWindow
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) shouldAutoRotate
{
return YES;
}
Upvotes: 4
Views: 6951
Reputation: 127
Click on your Project file in Xcode. Then click on 'Targets'. Choose you orientation (Scroll down!) Make sure in IB that the View (Under inspector) is set to portrait.
Upvotes: 0
Reputation: 1107
The rootViewController
-property was added to the UIWindow
-class in iOS 4. Usually this value is set in the UIApplicationDelegate
(in your case probably AppDelegate.m
). If the rootViewController
-property is not correct rotation-events sometimes don't get passed properly through the view-hierachy.
Try self.window.rootViewController = myRootViewController;
if it's not there already.
Upvotes: 0
Reputation: 1035
Are you using iOS 6.0 or higher? Then try implementing the preferredInterfaceOrientationForPresentation method also.
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
In case your root view is a UINavigationController you might want to subclass that and implement the new orientation methods in it.
When I want to support different default orientation in different UIViewController pushed to the same navigation controller I have a custom UINavigationControler kind of like this:
@implementation MyNavigationController
- (BOOL)shouldAutorotate;
{
return YES;
}
- (NSUInteger) supportedInterfaceOrientations
{
if ([[self topViewController] respondsToSelector:@selector(supportedInterfaceOrientations)])
return [[self topViewController] supportedInterfaceOrientations];
else
return [super supportedInterfaceOrientations];
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
if ([[self topViewController] respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)])
return [[self topViewController] preferredInterfaceOrientationForPresentation];
else
return [super preferredInterfaceOrientationForPresentation];
}
@end
Upvotes: 0
Reputation: 77
Just open your plist and edit the "Supported interface orientations" and drag the "Landscape (left home button)" to the top over the "Portrait (bottom home button)"
by default the top value is loaded first if you are supporting pre-iOS6 and running this in post-iOS6 SDK.
Upvotes: 0
Reputation: 912
Check post
Launching application in landscape orientation for IPad
Quoting jhhl from there:
setting the initial interface orientation in your info.plist is being ignored if you have Supported interface orientations set up with another orientation in the first slot! Put your initial orientation there as well - and the simulator will launch correctly, as will the app
Edit: one more thing - the problem may be in completely different place. Are you sure you have proper view controller hierarchy? If a controller has no been added the right way to the window or another controller the rotation events and logic will not work. In fact I just checked an app I wrote a couple of months ago which had the same issue - iPad, must start in landscape. Didn't take anything fancy, but setting the orientations in the Info.plist, attaching the rootViewController and setting the proper return values in the rotation methods.
Upvotes: 1
Reputation: 1469
It seems like you have all the rotation code properly implemented in your view controllers so maybe this is your problem. A while back i was in your shoes where i set up my code just how apple specified it to be in order to load my app in landscape mode but for some reason it just wasnt loading the app correctly. So after a bunch of forum posts and many many forum replies it turned out in my view controller i wasnt setting the view controllers view in loadView. So make sure in your load view method of the view controller the view you want the root view to be is set as is the view controllers self.view. Tell me how it goes
Upvotes: 1
Reputation: 2973
In older Xcode versions, all you have to do is go the .xib file, select the box with the arrows that says Portrait, and change it to Landscape, and then in the .m file, do:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
Upvotes: 0
Reputation: 9017
I hope this will help you.
Add one of this(which orientation you want) method in AppDelegate.m
class
For force fully run application in landscape mode:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
For force fully run application in Portrait mode:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
Upvotes: 7
Reputation: 1467
Try this, we had the same issue.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL returningValue=NO;
if (interfaceOrientation==UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
returningValue=NO;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
returningValue=YES;
}
return returningValue;
}
Upvotes: 0
Reputation: 1807
Prior to iOS 6 i.e in iOS 5 and earlier, an app and a view controller’s rotation is controlled by the individual viewcontrollers while in iOS 6 and later, the view controllers responsible for rotation are the container Viewcontrollers such as UINavigationController & UITabBarController . What are you using as the rootviewcontroller in your project??
Autorotation is clearly explained here in this post- Autorotation in iOS
Upvotes: 0
Reputation: 4533
Launching in Landscape Mode
In iOS 5 you need to implement the following method in everyone of your view controllers.
// Called only in IO 5 and earlier.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
}
And set UIInterfaceOrientation "Initial interface orientation " to UIInterfaceOrientationLandscapeRight in your Info.plist
And lay out your views in landscape mode.
Upvotes: 0
Reputation: 447
Check whether view controllers in the app force view orientation. Check section 'Handling View Rotations' and tasks related to rotation in Apple's documentation:
Upvotes: 3