すべての向きをサポートするアプリケーションを作成しました。アプリケーションがランドスケープモードで起動したときに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");
}
NSLog(@ "To Orientation:%d"、toInterfaceOrientation)を印刷できますか?結果を見せてください。 –
重複 - http://stackoverflow.com/questions/8775911/landscapeorientation-on-start-of-didload-method-in-objective-c/8775924#8775924 – rishi