iPadd アプリの向きを変更するときに問題が発生します。
サブビューをレイアウトする関数を作成して、ビューが表示されたり回転したりしたときに呼び出すことができるようにしました。
この関数は、「viewWillAppear」関数によって呼び出されると完全に機能します。しかし、「willAnimateRotationToInterfaceOrientation」関数がレイアウト関数 (「setPositionsForOrientation」) を呼び出すと、次の問題に直面しています。
- 縦から横に変更すると、左側に128pxのオフセットがあります
- 横向きから縦向きに変更すると、左側に負のオフセットがあります
私のUIScrollViewsもサイズ変更する必要があるため、どういうわけか新しいフレームプロパティが正しく処理されないという印象がありますが、そうしません。
それが私が書いたコードです:
- (void)viewWillAppear:(BOOL)animated{
[self setPositionsForOrientation:self.interfaceOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)newInterfaceOrientation duration:(NSTimeInterval)duration {
[self setPositionsForOrientation:newInterfaceOrientation];
}
- (void)setPositionsForOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Position the UI elements for landscape mode
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view.frame = CGRectMake(0, 0, 1024, 748);
self.menubarImage.frame = CGRectMake(0, 0, 1024, 121);
self.backgroundImage.frame = CGRectMake(0, 0, 1024, 748);
self.mainCategories.frame = CGRectMake(6, 6, 1012, 55);
self.subCategories.frame = CGRectMake(58, 79, 960, 30);
self.moviesContainer.frame = CGRectMake(6, 204, 1012, 456);
self.searchButton.frame = CGRectMake(935, 709, 80, 30);
}
// Position the UI elements for portrait mode
else {
self.view.frame = CGRectMake(0, 0, 768, 1004);
self.menubarImage.frame = CGRectMake(0, 256, 768, 121);
self.toolbarImage.frame = CGRectMake(0, 924, 768, 80);
self.backgroundImage.frame = CGRectMake(0, 256, 768, 748);
self.mainCategories.frame = CGRectMake(6, 262, 756, 55);
self.subCategories.frame = CGRectMake(58, 335, 704, 30);
self.moviesContainer.frame = CGRectMake(6, 460, 756, 456);
self.searchButton.frame = CGRectMake(680, 963, 80, 30);
}
}
そして、ここに私の問題を説明するためのいくつかの写真があります..
IB のレイアウト (すべてのサブビューで contentMode が Top-Left に設定されています)
http://www.abload.de/image.php?img=interfacebuilderl9ey.png
ポートレート モードが正しく表示される / おかしい
http://www.abload.de/image.php?img=portrait_oklxf1.png
http://www.abload.de/image.php?img=portrait_failma8y.png
ランドスケープ モードが正しく表示される / おかしい
http://www.abload.de/image.php?img=landscape_ok4z2l.png
http://www.abload.de/image.php?img=landscape_failvzuy.png
私は何を間違っていて、もっと重要なことをしましたか? どうすれば修正できますか? 通常の方法を説明するこの
投稿
を見つけましたが、ビューはUIViewControllerの単なるプロパティであるため、ビューの「layoutSubviews」メソッドをオーバーライドする方法がわかりません..