UIScrollView wrong offset with Auto Layout

前端 未结 7 996
逝去的感伤
逝去的感伤 2020-12-12 22:19

I have a fairly simple view configuration:

A UIViewController, with a child UIScrollView and a UIImageView in this UIScr

7条回答
  •  盖世英雄少女心
    2020-12-12 22:46

    Add a global property contentOffset and save the current contentOffset in viewDidDisappear. Once you return the method viewDidLayoutSubviews will be called and you can set your original contentOffset.

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
        [self.scrollView setContentOffset:self.contentOffset animated:FALSE];
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
        self.contentOffset = self.scrollView.contentOffset;
        [self.scrollView setContentOffset:CGPointMake(0, 0) animated:FALSE];
    }
    

提交回复
热议问题