4

わかりましたので、現在 3 つのビューがあり、そのうちの 1 つだけが任意の方向に自動回転する必要があり、残りは縦向きのままです。現在、私の設定は、splashviewcontroller がビュー A にフェードインし、ビュー A の内側にビュー B に切り替えるボタンがあります。ビュー B を任意の方向に回転できるようにするだけです。

スプラッシュ ビュー コントローラーで shouldautorotatetointerfaceorientation に対して YES を返すと、これが親ビューであるため、すべてのビューが回転します。スプラッシュ ビューでのみポートレートを返すと、他のビューが YES を返しても何も回転しません。ビュー B のみを回転させる方法はありますか? コードを提供できる場合は、手動で実行します。ありがとう

4

2 に答える 2

4

次のように、目的の UIView オブジェクトの回転を手動で管理できます。

編集:

init または viewDidLoad で

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotate) name:UIDeviceOrientationDidChangeNotification object:nil];

    [super viewDidLoad];
}

#define degreesToRadian(x) (M_PI * (x) / 180.0)

-(void)rotate{

    self.view.bounds = CGRectMake(0, 0, 0, 0);

    if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait){


        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
        landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);

        self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 320, 480);

        [self.view setTransform:landscapeTransform];


    } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortraitUpsideDown){


        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
        landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);

        self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 320, 480);

        [self.view setTransform:landscapeTransform];

    } else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight){

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));

         landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
         self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 480, 320); 


        [self.view setTransform:landscapeTransform];

    }else if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft){

        CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270));

        landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
        self.view.bounds = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, 480, 320); 

        [self.view setTransform:landscapeTransform];
    }

}
于 2011-11-07T22:12:51.763 に答える
0

ターゲットの概要セクション内で、サポートされているインターフェイスの向きのすべての項目が選択されています。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

これは私にとってはうまくいきました。

于 2013-01-14T12:05:41.527 に答える