UIScrollview Autolayout Issue

前端 未结 9 691
广开言路
广开言路 2020-12-05 07:19

I have a problem with autolayout(maybe) and my scrollview!

My Problem

  1. I scroll down \"View\"
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 07:20

    The issue cause ScrollView was set ContentOffset before AutoLayout applied. the solution is:

    Create private property

    @property (assign,nonatomic) CGPoint scrollviewContentOffsetChange;
    

    Add code to view method

    - (void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];
      self.scrollView.contentOffset = CGPointZero;
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
      [super viewWillDisappear:animated];
      self.scrollviewContentOffsetChange = self.scrollView.contentOffset;
    }
    
    - (void)viewDidLayoutSubviews {
      [super viewDidLayoutSubviews];
    
      self.scrollView.contentOffset = self.scrollviewContentOffsetChange;
    }
    

提交回复
热议问题