iPad开发UIScrollView在旋转屏幕的滚动问题

iPad开发中UIScrollView在旋转屏幕的问题:
问题描述:

UIScrollView分页,在滚动到非第一页时, 例如第5页,在此状态下旋转屏幕, 竖屏---->横屏,没有问题, 横屏---->竖屏,设置contentOffset每次旋转都会造成前移,或者出现 第三页和第四页等两页同屏的问题

问题代码说明:

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        self.scrollView.frame = self.view.bounds;
        for (NSInteger i = 0; i < _contentViewAr.count; i++) {
            UIView *viewC = _contentViewAr[i];
            viewC.frame = CGRectMake(i * self.view.bounds.size.width, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64 );
        }
        self.scrollView.contentSize = CGSizeMake(_contentViewAr.count * size.width, 0);
    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
          
        }
        if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
            self.scrollView.contentOffset = CGPointMake(self.scrollView.bounds.size.width  * _selectIndex, 0);
        }
    }];
}

根据以上的方式设置,解决问题,有咩有遇到同样问题的???图片描述

阅读 5.9k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题