2011-07-14 18 views
0

更新:私はそれがいつも同じビューを読み込んでいた理由を発見しました。私はそれを修正しました。これは、タイプミスオリエンテーションの変更を表示

ControllerForSplitViews.m

- (id)init 
{ 
    self = [super initWithNibName:@"ControllerForSplitViews" bundle:nil]; 
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){ 
     self.view = landscapeView; 
    } 
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 
     self.view = portraintView; 
    } 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 
    return self; 
} 

この作品でした。

今問題です。ビューが読み込まれて実行されているときに、向きを変えて同じnibファイルから別のビューを読み込むようにしました。固定しますが、これを実行すると直ちに他のUI要素が消えて横表示のui要素のみが保持されます。デバイスをもう一度回転すると、縦書きビューが再び表示されませんか?これがどうして起こるのか?

-(void) orientationChanged:(id)object 
{ 
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 
    { 
     self.view = portraintView; 
    } 
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 
    { 
     self.view = landscapeView; 
    } 
} 

という新たな問題、それは逆向きのビューロード

答えて

0

[OK]をおかげで私は働く修正を見つけ、私は向きを変更するたびに、私は分からないなぜ私の元のコードのdidn私が何をしたか「トンの仕事は:

削除:

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

削除:

-(void) orientationChanged:(id)object 
{ 
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 
    { 
     self.view = portraintView; 
    } 
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 
    { 
     self.view = landscapeView; 
    } 
} 

変更:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){ 

     self.view = landscapeView; 

    }else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || 
      (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){ 

     self.view = portraintView; 

    } 
    return YES; 
} 

そして今、それは私が今まで読み込み、これは、彼らがどここの投稿をチェックアウトする場合があります包み誰かのためにも、ここにこれを追加してい

+0

あなたの使用例UIViewControllerクラスです。では、すべてのUIViewControllerのUIViewControllerRotationカテゴリはどうですか? - '(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;などの回転のためのいくつかのメソッドがあります。 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; ' – beryllium

関連する問題