I suggest just making your application for portrait mode, and then whenever you need landscape mode, then enable landscape.
First, as previously suggested, click on → Project Name → General → Deployment Information → Select only a portrait for device orientation.
Secondly, in AppDelegate.h add this property.
@property (nonatomic) BOOL fullScreenVideoIsPlaying;
Then, on your AppDelegate.m , I will add this function.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if (self.fullScreenVideoIsPlaying == YES) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return UIInterfaceOrientationMaskPortrait; } }
After that, in the view controller that you need the landscape, create a function or just add this code to your viewWillAppear method, depending on how you want to accomplish this.
((AppDelegate *)[[UIApplication sharedApplication] delegate]).fullScreenVideoIsPlaying = YES; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
Then, to return to portrait mode, you do this.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.fullScreenVideoIsPlaying = NO; [self supportedInterfaceOrientations]; [self shouldAutorotate:UIInterfaceOrientationPortrait]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
You may need these features for iOS 8 ..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{ // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; }
Hope this helps .. :)