2012-01-10 5 views
1

すべての向きをサポートするアプリケーションを作成しました。アプリケーションがランドスケープモードで起動したときにUIOrientationが機能しない

また、(xibを使用しないで)viewDidLoadメソッドでテーブルと検索バーを作成しました。私はまた、テーブルビューと検索バーの位置を調整するために次のコードを書いています。

私のアプリケーションをポートレート表示で起動すると正しく動作し、横画面表示にすると完全に表示が調整されます。

しかし、アプリケーションをランドスケープモードで起動すると、ビューが調整されず、代わりにポートレートビューの位置付けが行われます。しかし、もう一度私が肖像画で回転し、その後風景が正常に動作します。

正しい向きが得られるように、私はNSLogと書いてあり、正しい値を示しています。

また、このメソッド(adjustViewsForOrientation)が明示的に呼び出されるように、私はviewDidLoadにメソッドを呼び出しました。ここで

[self adjustViewsForOrientation:self.interfaceOrientation]; 

は、コードスニペットの残りの部分である:

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
    if (orientation == UIInterfaceOrientationLandscapeLeft || 
      orientation == UIInterfaceOrientationLandscapeRight) { 
     aTableView.frame = CGRectMake(705, 220, 320, 280); 
     sBar.frame=CGRectMake(805, 0, 220, 40); 
     NSLog(@"inside landscape");   
    } 
    else if (orientation == UIInterfaceOrientationPortrait || 
       orientation == UIInterfaceOrientationPortraitUpsideDown) { 
     aTableView.frame = CGRectMake(450, 220, 320, 280); 
     sBar.frame=CGRectMake(550,3,220,40); 
    } 
} 

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 
    // [self adjustViewsForOrientation] 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
    NSLog(@"landscap"); 
} 
+0

NSLog(@ "To Orientation:%d"、toInterfaceOrientation)を印刷できますか?結果を見せてください。 –

+0

重複 - http://stackoverflow.com/questions/8775911/landscapeorientation-on-start-of-didload-method-in-objective-c/8775924#8775924 – rishi

答えて

0

は、それが役立つことがあり、この方法を試してみてください。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustViewsForOrientation:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

をしても-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation

-(void) adjustViewsForOrientation:(NSNotification *)notification

を変更し、

例えばオリエンテーション値を取得することで、新たな方向性を得る:viewDidLoadメソッドでUIDeviceOrientationDidChangeに登録UIDeviceOrientation newDeviceOrientation = [notification orientation];

関連する問題