-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

4

1 回答 1

0

在 github 上查看这个项目 https://github.com/alloy/ForceOrientationTest

在此处输入图像描述

于 2013-10-07T13:12:53.537 回答