UIScrollview Autolayout Issue

前端 未结 9 670
广开言路
广开言路 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:41

    This isn't great but I beat auto-layout (definitely not the correct way but I was sick of trying!) by setting the content size in viewDidAppear after autolayout happens, setting the scrollOffset and persisting the scroll offset in viewDidDisappear, and then setting the scroll offset back to it's persisted state in viewDidAppear.

    Like this:

    -(void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear:YES];
        self.scrollView.contentSize = self.scrollViewInnerView.frame.size;
        self.scrollView.contentOffset = [self.scrollOffsetToPersist CGPointValue];
    
    }
    
    -(void)viewDidDisappear:(BOOL)animated{
        [super viewDidDisappear:YES];
        self.scrollOffsetToPersist = [NSValue valueWithCGPoint:self.scrollView.contentOffset];
        self.scrollView.contentOffset = CGPointZero;
    }
    

    Not at all elegant, but works so thought I'd share.

提交回复
热议问题