-1

カテゴリを使用してみました....新しいファイルを追加し、カテゴリを選択してサブクラス UINavigationController クラスを作成します。

.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 は App デリゲートで天気をチェックするために宣言されています。

今FirstViewController.mファイル私はPortaritモードでそれをしたいので、このコードを使用しました

- (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;
}

および SecondViewController ランドスケープ モードでこれを使用する必要があります。

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

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

私はこのProtraitの最初のViewControllerとLandscape ModeのSecondViewController、およびこのLandscape Apps Xcode 5 / iOS 7などを参照していますが、私にとっては機能していません

4

1 に答える 1

0

github でこのプロジェクトを ご覧ください https://github.com/alloy/ForceOrientationTest

ここに画像の説明を入力

于 2013-10-07T13:12:53.537 に答える