7

以下のように、iOS 5.x で方向チェックを動的に行います。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==         UIInterfaceOrientationPortraitUpsideDown) 
 {
self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
// some more settings
}
else
{
self.profileNew.frame = CGRectMake(374, 540, 295, 58);
 // some more settings
}
 return YES;
}

iOS 6 の場合、以下のコードを実行しましたが、機能しません。

-(BOOL)shouldAutorotate{    
   return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
 if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) 
  {
   self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
   // some more settings
  }
  else
  {
   self.profileNew.frame = CGRectMake(374, 540, 295, 58);
   // some more settings
  }
 return UIInterfaceOrientationMaskAll;
}

iOS 5.x で行ったのと同じように、iOS 6 でインターフェイスの向きを確認するにはどうすればよいですか?

ありがとう

4

4 に答える 4

9

viewWillLayoutSubviews向きを確認する方法を使用できます

[[UIApplication sharedApplication] statusBarOrientation];

それに応じてフレームを設定します。

お役に立てれば!

于 2012-12-20T08:43:52.917 に答える
4

このメソッドでチェックを実行してみてください

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
                            duration:(NSTimeInterval)duration

編集:

これを使って:

BOOL isInPortrait = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]);
于 2012-12-20T08:44:11.893 に答える
1

Levi's と Nikola Kirev の回答を組み合わせて、コードが正しく機能するようになりました。お二人ともありがとう。他の人が参照するコードは次のとおりです。

iOS 6 の場合:

 -(BOOL)shouldAutorotate{
    return YES;
  }


-(NSInteger)supportedInterfaceOrientations{
        if (UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
            self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
            //other codes            
        }

        else {
            self.viewProfile.frame = CGRectMake(374, 462, 295, 58);
            //other codes
        }
        return UIInterfaceOrientationMaskAll;
       }

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
                            duration:(NSTimeInterval)duration{
    if (UIDeviceOrientationIsPortrait(orientation)) {
        self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
        //other codes
        self.profileNew.frame = CGRectMake(238, 713, 295, 73);            
    }

    else {
        self.viewProfile.frame = CGRectMake(374, 462, 295, 58);
        //other codes
    }
}

iOS 5.x および 4.x の場合

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
        //other codes      
    }

    else {
        self.viewProfile.frame = CGRectMake(374, 462, 295, 58); 
        //other codes
        }
    return YES;
    } 
}
于 2012-12-21T04:16:55.727 に答える
0

これを試して :

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]
于 2012-12-20T08:47:48.587 に答える