4

この質問は今までに何百万回も尋ねられるべきだったと思いますが、私はまだこれに対する答えを見つけることができません.

ここに私の階層があります: UINavigationController -> UIViewController 1 -> (プッシュ) -> UIViewController 2

UINavigationController: 可能なすべての向きをサポートします UIViewController 1: 縦向きのみをサポートします UIViewController 2: 横向きのみをサポートします

UIViewController 1 をポートレートのみにロックし、同時に UIViewController 2 をランドスケープのみにロックするにはどうすればよいですか? それは可能ですか?これまでのところ、UIViewController 2 は常に UIViewController 1 の方向をとっています。

これは iOS 6 専用であることに注意してください。

ありがとう!

4

3 に答える 3

13

私も同じ問題を見つけました.shouldAutorotate関数が毎回呼び出されないことがわかったので、向きをプログラムで変更します

最初にこれをインポートします

#import <objc/message.h>

それから

-(void)viewDidAppear:(BOOL)animated
{

     if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );


        }
    }

}

これがお役に立てば幸いです。

于 2013-05-04T05:24:39.237 に答える
1

アプリが縦向きモードのみをサポートするようにし、UIViewController 2 の initWithNibName に次の行を追加します。

self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
于 2013-05-04T15:30:32.817 に答える