UIScrollView's origin changes after popping back to the UIViewController

后端 未结 17 2218
不知归路
不知归路 2020-12-07 16:50

I have a UIViewController subclass as a scene in the storyboard that contains a UIScrollView containing various subviews. One of the subviews is a

相关标签:
17条回答
  • 2020-12-07 17:08

    i had a similar problem, after dismissing a viewController, the contentOffset from my tableView was changed to (0, -64).

    my solution was a little weird, i tried all the other answers but had no success, the only thing that fixed my problem was to switch the tableView position in the controls tree of the .xib

    it was the first control in the parent View like this:

    before

    I moved the tableView right after the ImageView and it worked:

    after

    it seems that putting the table view in the first position was causing the trouble, and moving the table view to another position fixed the problem.

    P.D. I'm not using autoLayout neither storyboards

    hope this can help someone!

    0 讨论(0)
  • 2020-12-07 17:08

    Just in case none of the above helped, I had this issue as well as the issue for me was that i had the following code..

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        tableView.reloadData()
    }
    

    Commenting out this reloadData() line fixed the issue for me. I didn't need this line so not sure why i even added it!

    Hopefully this solution helps someone else.

    0 讨论(0)
  • 2020-12-07 17:10

    I'm using a collectionView and I had a similar problem. For iOS 11: in the size inspector, there is "content inset". Set that to "Never". That solved the problem for me. I hope this helps someone.

    Objective C:

    if (@available(iOS 11, *)) {
       [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    

    Swift:

    if #available(iOS 11, *) {
    UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
    }
    
    0 讨论(0)
  • 2020-12-07 17:10

    Turn off AutoLayout option for that xib otherwise.

    0 讨论(0)
  • Have you tried checking the Extend Edges Under Opaque Bars option? It can be found in your controller attributes inspector inside the storyboard.

    It did the trick for me using XCode 9 iOS 11.

    0 讨论(0)
提交回复
热议问题