-1

I tried using a Category.... Add new files and select Category and make subclass UINavigationController class.

here is the code for category for .h

    #import <UIKit/UIKit.h>
    #import "AppDelegate.h"

    @interface UINavigationController (orientation)

    @end

code for .m file

#import "UINavigationController+orientation.h"

@implementation UINavigationController (orientation)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{

    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    if (delegate.islandscape)
    {
        // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
        return UIInterfaceOrientationMaskLandscape;

    }
    return UIInterfaceOrientationMaskPortrait;

}
@end

isLandscape is declared in App delegate to check weather First view controller or secondView Controller isLandscape is Bool.

Now FirstViewController.m file i want that in Portarit mode so used this code

- (IBAction)PlayClicked:(id)sender
{
    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];


    self.navigationController.navigationBarHidden=YES;
    delegate.islandscape=YES;

    ViewController * v=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

    [self presentViewController:v animated:NO completion:nil];


    //[self dismissViewControllerAnimated:YES completion:nil];
   [self.navigationController pushViewController:v animated:YES];

}


- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

and SecondViewController i want that in Landscape mode used this one.

delegate.islandscape=NO;   // called transfer to Category 

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

I refer this 1st ViewController in Protrait and SecondViewController in Landscape Mode and this Landscape Apps Xcode 5 / iOS 7 and other but not working for me

Community
  • 1
  • 1
SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45

1 Answers1

0

Have a look at this project on github https://github.com/alloy/ForceOrientationTest

enter image description here

SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45
iAhmed
  • 6,556
  • 2
  • 25
  • 31
  • its not woking in my app but i add my project in this Demo and it woking fine – SAMIR RATHOD Oct 11 '13 at 12:29
  • i faced same issue, i resolved it by presenting viewcontroller rather than navigation controller – iAhmed Oct 26 '13 at 06:28
  • hi, but there is one problem when i push the view in landscape then rotate the simulator or device then back to portrait view then the view is portrait but device and simulator are in landscape see image – SAMIR RATHOD Oct 26 '13 at 07:28
  • see my question http://stackoverflow.com/questions/19651657/rotate-portrait-to-landscape-in-pdfreader-in-ios6-and-ios7 – SAMIR RATHOD Oct 29 '13 at 07:00