をiOS5を上に私のアプリをテストするとき、私は同様の問題に直面していたサブビューのレイアウトをめちゃめちゃに取得するために使用メインビューコントローラに向きが変更された場合。モーダルビューコントローラがアクティブであったとき。
私はメインコントローラに現在の方向フラグを保存することでした。このフラグは、メインコントローラ
- willAnimateRotationTに2つの場所で更新され、何
oInterfaceOrientation:
- viewWillLayoutSubviews(これが唯一のiOS5をオン)
Iが格納された値と現在の方向を比較することによりサブビューを調整するすべてのロジックを書きます。それらが異なる場合 - 保存された方向を更新して、サブビューを更新します。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Any orientation is OK
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
portrait = UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
// Code to update subview layout goes here
}
-(void)viewWillLayoutSubviews
{
BOOL isPortraitNow = UIInterfaceOrientationIsPortrait(self.interfaceOrientation);
if(isPortraitNow != portrait)
{
DLog(@"Interfaceorientation mismatch!, correcting");
portrait = isPortraitNow;
// Code to update subview layout goes here
}
}
iOS 5はまだNDAの下にあります –