If your application uses the UINavigationViewController, then create a custom class for the UINAvigationController Like:
//CustomNavViewController.h
#import <UIKit/UIKit.h> @interface CustomNavViewController : UINavigationController <UINavigationControllerDelegate> @end
//CustomNavViewController.m
And now in your AppDelegate declare a Like property:
//AppDelegate.h
@property (assign, nonatomic) BOOL shouldRotate;
//AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (self.shouldRotate) { return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight; } return UIInterfaceOrientationMaskPortrait; }
Now you can call the orientation methods in the ViewController, which require a fixed orientation. How:
//YourViewController.m
-(BOOL)shouldAutorotate{ return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationLandscapeLeft; }
Now here is the AppDelegate shouldRotate trick set is true and false for the desired orientation
if you use the default view for the ViewController then
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate setShouldRotate:true];
Same as releasing
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate setShouldRotate:false]; [self dismissViewControllerAnimated:YES completion:nil];
If you are using storyBoards, add the CustomNavViewController directly to the Custom class section of the Inspector Custom class
And then follow these steps. Hope it works.