0

この問題に関連する多くの質問があることは承知していますが、私の問題を解決する質問は見つかりませんでした。

まず、このコードを menu.h に設定しました。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    
return YES; }

ステータス バーは方向によって変化しますが、ビューは回転またはサイズ変更されません。問題を絞り込むために、方向に基づいて 1 つの .xib 内で 2 つのビューを切り替えることにしました。

    - (void)viewDidLoad {
    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
     }
    -(void) orientationChanged:(NSNotification *)object
{
   UIDeviceOrientation deviceOrientation = [[object object] orientation];

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
    {
        self.view = self.landscapeView;
    }
    else 
    {
        self.view = self.portraitView;
    }
}

iOS シミュレーターでは、ビューは確実に特定のビューに変わります。ただし、横向きのビューは、縦向きで横向きのように表示されます。

IB での私の横向きビュー ここに画像の説明を入力

向きを変更した後の iOS シミュレーターの横向きビュー ここに画像の説明を入力

ここで何が間違っていますか?私はそれを理解できません、どんな助けでも大歓迎です。前もって感謝します。** 編集: 以下の新しいコード ** わかりました..私の問題は、ビューが横向きに正しく読み込まれることです。横向きです。そのため、Landscape ビューがロードされ、横向きになります。@Seegaに基づく私の修正されたコードは次のとおりです。

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

    [[TTNavigator navigator] setCustomTarget:self];
    [[TTNavigator navigator] setCustomAction:@selector(photoAction)];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight)
    {
        self.view = self.landscapeView;
    }
    else 
    {
        self.view = self.portraitView;
    }
}

-(void) orientationChanged:(NSNotification *)object
{
    UIDeviceOrientation deviceOrientation = [[object object] orientation];

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
    {
        self.view = self.landscapeView;
    }
    else 
    {
        self.view = self.portraitView;
    }
}
4

5 に答える 5

4

コードを次の場所に配置することをお勧めします。

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

新しい方法を作る代わりに。shouldAutorotateToInterfaceOrientation メソッドがその回転に対して YES を返す場合、これは自動的に呼び出されます。

また、UIDeviceOrientation と UIInterfaceOrientation には違いがあるため、正しいものを参照していることを確認してください。既存のコードは次のように変更されます。

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    self.view = self.landscapeView;
}
else 
{
    self.view = self.portraitView;
}

また、マクロを使用してインターフェイスの向きをチェックし、コードをよりクリーンに保つことができます。

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
{
    self.view = self.landscapeView;
}
else 
{
    self.view = self.portraitView;
}
于 2012-04-16T18:42:04.420 に答える
1

アイディア!!!

Interface Builderでビューを設定し、ビューが回転したときに表示される実際のビューを切り替える場合は、方向に合わせてサイズを変更するだけでなく、その特定の方向でビューを作成する必要があります。

これを確認するには:

  • InterfaceBuilderで.xibを開きます。
  • オブジェクトの下にある[ビュー]をクリックして、ビュー全体を選択します。
  • IBの右側にある「シミュレートされたメトリック」の下を見てください。[向き]ドロップダウンで[横]が選択されていることを確認します。

ビューがlandscapeViewを表現したいビューに対して「Portrait」と表示されている場合は、xcodeがランドスケープビューをポートレートに回転し、プレゼンテーションを混乱させている可能性があります。

これが役に立ったかどうか教えてください。

于 2012-04-16T20:09:17.670 に答える
1

単純に使用する方がよい

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.view = self.landscapeView;
    }
    else 
    {
        self.view = self.portraitView;
    }
}

独自の回転を​​作成する代わりに回転を処理します。
これで、すべての通知を削除できます。

于 2012-04-16T18:19:28.487 に答える
1

次のようにすべての方向サポートが選択されていることを確認できますか。私はこれを試しましたが、私にとってはうまく機能しているようです。

ここに画像の説明を入力

于 2012-04-16T18:19:49.780 に答える
0

ねえ、あなたの助けをありがとう。私は友人に助けてもらいましたが、問題があったかどうかは完全にはわかりません. 彼がしたことを私が知っていることをあなたに話すことができます。

  1. 広告を一時的に無効にしました

  2. 2番目のビューを完全に削除し、ネイティブの向きとサイズ変更を行いました

  3. これをほぼすべての .m ファイルに追加しました。

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    
    return YES;
    

    }

  4. 同様に、これに似た他のいくつかのビューをプログラムで変更しました

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
         if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight)
         {
              if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) 
              {         
                   self.Button.frame = CGRectMake(27,96,86,86);
                   self.Label.frame  = CGRectMake(27,162,86,21);
              }
             else 
             {
                   self.Button.frame = CGRectMake(18,100,86,86);
                   self.Label.frame  = CGRectMake(18,164,86,21);
              }
         }
     } 
    

申し訳ありませんが、答えを完全に説明することはできません。オリエンテーションに影響を与えたプロジェクトに含まれていたすべてのことを完全には理解していません。私はまだiOS開発に非常に慣れていません。

于 2012-04-28T14:07:10.987 に答える