1

デバイスの向きを確認し、メソッドを呼び出して向きviewDidAppearviewWillAppear強制しwillAnimateRotationToInterfaceOrientationます。

 - (void) viewWillAppear:(BOOL)animated
   {
     [super viewWillAppear:YES];
     _levelComplete = YES;

     [self willAnimateRotationToInterfaceOrientation:[[UIDevice currentDevice] orientation] duration:0.01];

   }

 - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight) )
     {

     }
     else  if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
     {

     }
 }

私が直面している問題は、両方ともメソッドtoInterfaceOrientationが0のままである ため、プログラムがクラッシュすることです。viewDidAppearviewWillAppear

何が問題なのでしょう?

助けてください!

4

2 に答える 2

2

これを試して

    - (void) viewDidLoad
       {
         _levelComplete = YES;

        [self adjustViewsForOrientation:self.interfaceOrientation];

       }
    -(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
   {

      if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
        {

        }
        else
        {
        }
 }
于 2013-03-01T05:35:33.067 に答える
0

あなたが言ったように:私が直面している問題は、viewDidAppearメソッドとviewWillAppearメソッドの両方でtoInterfaceOrientationが0のままであるため、プログラムがクラッシュすることです。

方向0は、未知の方向を示します。オリエンテーションデリゲートにブレークポイントを設定しviewWillAppearます。viewDiddAppear方向の遅延は、ビューデリゲートの最初に呼び出されることに注意してください。

デリゲートを使用できます

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{
  return UIInterfaceOrientationLandscapeLeft;
}

このデリゲートを使用すると、アプリケーションはランドスケープモードまたは任意の方向モードで表示されます。

それを試してみてください。

于 2013-03-01T06:00:08.243 に答える