这有点奇怪。
我有一个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;
}
其他一切在我的应用程序中完美运行,这是我提交之前的最后一个错误,怪癖。