This is a bit of an odd one.
I have a UIScrollView with 5 pages and have device rotation set up.
If I have the UIScrollView on page 1,2,3 or 4 and rotate from either portrait to landscape, or landscape to portrait then the correct corresponding page is shown. i.e. if i'm on page 2 in portrait and switch orientation then page 2 is shown when in landscape.
However if I am on page 5 and switch from landscape to portrait it correctly shows page 5, but if I switch from portrait to landscape then it bizarrely shows page 3!!
Any ideas would be gratefully appreciated.
Heres the code parts:
- (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;
}
Everything else works perfectly in my app and this is the last bug, quirk, before I submit it.