Question

Can I disable rotation for all screens neither one for iPhone. And how can I do it? I do a lot of combinations with initial portrate/landscape and follow methods but not get it. If I have enable landscape in app settings all screens are rotates. I can not now use device, I test it on simulator.

 - (BOOL)shouldAutorotate
 {
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
 {
//Choose your available orientation, you can also support more tipe using the symbol |
//e.g. return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight)
return (UIInterfaceOrientationMaskPortrait);
}
Was it helpful?

Solution

i ran into the same problem first of all check mark on all orientation in built setting>targets>deployment info. then in your app delegate file implement this:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

UIViewController *currentViewController = [self topViewController];

// Check whether it implements a dummy methods called canRotate
if ([currentViewController respondsToSelector:@selector(canRotate)]) {
    // Unlock landscape view orientations for this view controller
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

// Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;

}

-(UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];

}

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{     

if ([rootViewController isKindOfClass:[UINavigationController class]]) { UINavigationController* aNavigationController = (UINavigationController*)rootViewController;

    return [self topViewControllerWithRootViewController:aNavigationController.visibleViewController];

}
else
{
    return rootViewController;
}

}

in your view controller(assume E) which you want to be in portrait/landscape..

add this:

//run time flag method

-(void)canRotate//also declare in header file {

}

- (BOOL)shouldAutorotate

{ return YES; }

you are done.

for more info you can go to this link

OTHER TIPS

You need to subclass the UINavigationController and embed your ViewControllers in the navigation controller.

@implementation CustomNavigationController
// -------------------------------------------------------------------------------
//  supportedInterfaceOrientations:
//  Overridden to return the supportedInterfaceOrientations of the view controller
//  at the top of the navigation stack.
//  By default, UIViewController (and thus, UINavigationController) always returns
//  UIInterfaceOrientationMaskAllButUpsideDown when the app is run on an iPhone.
// -------------------------------------------------------------------------------
- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations]; 
}
// -------------------------------------------------------------------------------
//  shouldAutorotate
//  Overridden to return the shouldAutorotate value of the view controller
//  at the top of the navigation stack.
//  By default, UIViewController (and thus, UINavigationController) always returns
//  YES when the app is run on an iPhone.
// -------------------------------------------------------------------------------
- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}  

For each ViewController, you can override their shouldAutorotate and supportedInterfaceOrientations methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top