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);
}
}];
}
根据以上的方式设置,解决问题,有咩有遇到同样问题的???
你可以尝试在viewWillAppear中进行旋转屏幕的
https://stackoverflow.com/que...
具体的你可以看看kkklc的回答,
也是本人撰写的。