デバイスのインターフェイスの向きに適応する必要がある UIScrollView (pagingEnabled) を使用してアプリを作成しようとしています。
これを行うために、UIImageviews と UIButtons を搭載した 2 つの UIScrollViews とアニメーション (CA) を作成しました。1 つはポートレート用、もう 1 つはランドスケープ用です (コードで確認できます)。
今私の問題は、デバイスを回転させるたびに、はい! 向きの変更には応答しますが、最初のページに戻ります。
これはわかりました...あなたはすでに縦向きのscrollViewの10ページ目にいますが、横向きに切り替えると再び最初のページになります。
私はそれを明確に説明したいと思います。
そして...回転するとiPadでクラッシュします。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
//self.view = portraitView;
[self changeTheViewToPortrait:YES andDuration:duration];
}
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
//self.view = landscapeView;
[self changeTheViewToPortrait:NO andDuration:duration];
}
}
- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
if(portrait){
//change the view and subview frames for the portrait view
[self forPortrait];
[self removeMainSVLContents];
}
else{
//change the view and subview frames for the landscape view
[self forLandscape];
[self removeMainSVPContents];
}
[UIView commitAnimations];
}
「forPortrait」の内容は「forLandscape」と同じで、フレームが異なるだけで、縦向きと横向きの画面に合うように異なる画像があります。