美文网首页
iOS - UISCrollView 屏幕旋转后视图有偏移

iOS - UISCrollView 屏幕旋转后视图有偏移

作者: 呦释原点 | 来源:发表于2018-07-13 16:14 被阅读46次
    -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
    {
        [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
        
        CGFloat width =  self.scrollView.frame.size.width;
        CGFloat Height = self.scrollView.frame.size.height;
        
        [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
            
    //        self.scrollView.frame = self.view.bounds;
           
            for (NSInteger i = 0; i < self.contentViewAr.count; i++) {
                UIView *viewC = self.contentViewAr[i];
                viewC.frame = CGRectMake(i * Height, 0, Height, width);
            }
            self.scrollView.contentSize = CGSizeMake(self.contentViewAr.count * Height, 0);
        } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
            if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
                if (self.selectIndex>0) {
    //                self.scrollView.contentOffset = CGPointMake(Height  * self.selectIndex, 0);
                    [self.scrollView setContentOffset:CGPointMake(Height  * self.selectIndex, 0) animated:YES];
    
                }
            }
            if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
    //            self.scrollView.contentOffset = CGPointMake(Height  * self.selectIndex, 0);
                [self.scrollView setContentOffset:CGPointMake(Height  * self.selectIndex, 0) animated:YES];
            }
        }];
    }
    
    

    相关文章

      网友评论

          本文标题:iOS - UISCrollView 屏幕旋转后视图有偏移

          本文链接:https://www.haomeiwen.com/subject/igqspftx.html