Default Application Orientation

I have an application written in an old version of Xcode. I am currently using Xcode 4.6.1. This is an application that I inherited from another developer that was developed outside the company.

One of the problems with this application is its interface. It should use LandscapeLeft by default (this is the value set in the pList file). An application ignores this directive and instead performs default portrait mode.

Is there anything I need to do to get the code to abide by this value? I am relatively new to iOS / Objective-C. The code compiles and runs, it's just that the interface does not do what I want.

This is a little easier since this is an iPad app.

Edit I tried adding the following code to one of my problematic viewControllers, but this is not respected. Any thoughts on how to get this view to change the landscape? (Is there a setting in the IDE - it looks like Xcode is used for the orientation attribute, but I cannot 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;
}
+5
source share
12 answers

Hope this helps you. Add one of this method (which you need) to the AppDelegate.mclass

To force the application to start in landscape mode:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskLandscape;
}

To force the application to start in portrait mode:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}
+5
source

, , , , , . , , Apple , , - . , , , loadView. , , , , view views self.view. , .

+1

Xcode. "". ( !) , "" ( " " ) "".

0

iOS 5 .

// Called only in IO 5 and earlier.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft );
}

UIInterfaceOrientation " " UIInterfaceOrientationLandscapeRight Info.plist

.

Per Apple

0

iOS 6, iOS 5 , iOS 6 , , , UINavigationController UITabBarController. rootviewcontroller ?

iOS

0

, .

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    BOOL returningValue=NO;

    if (interfaceOrientation==UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
        returningValue=NO;
    }
    else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
    {
        returningValue=YES;
    }

    return returningValue;
}
0

Xcode , , .xib, , "", "", .m :

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
 }
0

IPad
jhhl :

info.plist , , ! - ,

: - . , ? , . , , ​​ - iPad, . , Info.plist, rootViewController .

0

" " " ( )" " ( )"

, pre-iOS6 SDK iOS6.

0

iOS 6.0 ? preferredInterfaceOrientationForPresentation.

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

, UINavigationController, .

When I want to support different default orientations in another UIViewController pressed on the same navigation controller, I have a custom UINavigationControler type that looks 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
0
source

rootViewController-property was added to the class UIWindowin iOS 4. Typically, this value is set to UIApplicationDelegate(in your case, probably AppDelegate.m). If rootViewController-property is not true, occasional events are sometimes not properly passed through view-hierachy.

Try self.window.rootViewController = myRootViewController;it if it no longer exists.

0
source

All Articles