3

これはちょっと変わったものです。

5 ページの UIScrollView があり、デバイスの回転が設定されています。

ページ 1、2、3、または 4 に UIScrollView があり、縦向きから横向き、または横向きから縦向きに回転すると、対応する正しいページが表示されます。つまり、縦向きで 2 ページ目にいるときに向きを切り替えると、横向きのときに 2 ページ目が表示されます。

ただし、5 ページで横向きから縦向きに切り替えると、5 ページが正しく表示されますが、縦向きから横向きに切り替えると、奇妙に 3 ページが表示されます。

任意のアイデアをいただければ幸いです。

コード部分は次のとおりです。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
    [self switchToLandscape];
    }
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
    [self switchToPortrait];
   }
}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat distance = hsScroll.bounds.size.width;
NSInteger pageNumber = floor((hsScroll.contentOffset.x - distance / 2) / distance) + 1;
hsPC.currentPage = pageNumber;
currentPage = pageNumber;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
}

- (void)switchToPortrait {
//lots of other stuff relating to moving things around
[hsScroll setContentOffset:CGPointMake((currentPage * 320), 0) animated:NO];
hsPC.currentPage = currentPage;
}

- (void)switchToLandscape {
//lots of other stuff relating to moving things around

[hsScroll setContentOffset:CGPointMake((currentPage * 480), 0) animated:NO];
hsPC.currentPage = currentPage;
}

他のすべては私のアプリで完全に機能し、これが提出前の最後のバグ、癖です。

4

0 に答える 0