0

I have been developing an app which requires orientation only for one view, for which I require a way to detect the current view in the appdelegate page

Can anyone please help and tell me how this is possible

Regards,

Neha

Neha Dangui
  • 597
  • 2
  • 13
  • 28
  • do you want to know that which is the current orientation....? – Ashish Ramani Jun 16 '14 at 12:39
  • No, I dont want to know the current. I just wanted to know if it is possible to allow only one of the views in the app with landscape view and not allowing the others. Also i wanted to know if it is possible to find out which is the currently viewed view in appDelegate page. – Neha Dangui Jun 16 '14 at 12:42
  • Your primary question is a duplicate of the noted question; your secondary question is a duplicate of http://stackoverflow.com/questions/11637709/get-the-current-displaying-uiviewcontroller-on-the-screen-in-appdelegate-m – Jesse Rusak Jun 16 '14 at 12:59

1 Answers1

0

You can specify the app's supported orientations here:

Device Orientations

If you select only Portrait then you essentially lock your app in the Portrait mode

EDIT:


If you want all your viewControllers to be locked in Portrait mode but allow multiple orientations to a single/selected viewController(s) then you could implement this quick fix:

In the viewController that allows multiple orientations:

-(void)viewWillAppear:(BOOL)animated
{
    [[NSUserDefaults standardUserDefaults] setObject:@(YES)
                                              forKey:@"allowLandscape"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [[NSUserDefaults standardUserDefaults] setObject:@(NO)
                                              forKey:@"allowLandscape"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

In your AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //...
    //default setting when app starts
    [[NSUserDefaults standardUserDefaults] setObject:@(NO)
                                              forKey:@"allowLandscape"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //...
}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"allowLandscape"] boolValue]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }

    return UIInterfaceOrientationMaskPortrait;
}
staticVoidMan
  • 19,275
  • 6
  • 69
  • 98