2

タブバーアプリケーションがあります。XCode4.3.3を使用していました。iOS6のもので4.5.2にアップグレードしました。

各ビューのコードはshouldAutorotateToInterfaceOrientation、現在のデバイスの向きを確認し、すべてのUIコンポーネントを適切に配置します。

しかし、iOS 6にアップグレードした後、このコードは実行されません。私はこれを修正するためにほぼ1日試みましたが、運がありませんでした。

私も試しました

UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation]; 

viewLoad、、viewDidLoad_viewWillAppear

ビューの読み込み中に向きを確認し、ビューの読み込み中にUIコンポーネントを適切な場所に配置する場合はどうすればよいですか。親切にあなたの提案をしてください。

ありがとう

4

4 に答える 4

11

どちらが現在の向きであるかを確認したい場合は、行の下の prifix.pch に書き込むだけです

 #define isPortrait [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown

次に、向きを確認したい場所に、以下のように条件を書きます

    if(isPortrait)
    {
       //portrait mode....
    }
    else
    {
       //landscape mode....
    }

それが機能しているかどうかを教えてください...

ハッピーコーディング!

于 2013-01-07T12:10:18.963 に答える
2

iOS6で方向を確認するには、以下のメソッドを記述し、info.plistで必要な方向を定義する必要があります...

それが機能しているかどうかを教えてください!!!

ハッピーコーディング!!!!

   - (BOOL)shouldAutorotate{
     return NO;
   }

   - (NSUInteger)supportedInterfaceOrientations{
      return UIInterfaceOrientationMaskPortrait;//you can write here which ever orientation you want..
   }
于 2013-01-07T04:33:55.320 に答える
2

あなたはこのようにオリエンテーションを管理します:-

-(BOOL)shouldAutorotate
{
    return YES;
}

ViewWillApearそして、次のようなデバイスの向きで毎回チェックしてください:-

- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
        if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        {
            if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {

              //set your landscap View Frame
                [self supportedInterfaceOrientations];

            }



        }
        else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        {
            if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
      //set your Potrait View Frame
                [self supportedInterfaceOrientations];

            }
        }
        // Handle rotation
    }


    -(void)viewWillAppear:(BOOL)animated
    {
        [self willRotateToOrientation:[[UIDevice currentDevice] orientation]];  
        [super viewWillAppear:YES];
    }

アップデート

orientationおそらく人々は、この行を次の場所に入れる際に、以下のようなチェックデバイスを使用しViewWillApearます

[[UIApplication sharedApplication] statusBarOrientation];
    [[UIDevice currentDevice] orientation];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

-(void)deviceRotated:(NSNotification*)notification
{

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        //Do your stuff for landscap
    }
    else if(orientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
      //Do your stuff for potrait

    }

}
于 2013-01-07T05:06:37.763 に答える