ios UIScrollView have a bad default contentOffset - swift

前端 未结 3 1163
深忆病人
深忆病人 2021-01-11 09:22

I have a View inside a ScrollView inside my main View

The problem is that my scrollView have a bad default contentOffset. His value is (0, -64) in portrait

T

相关标签:
3条回答
  • 2021-01-11 10:07

    Swift 4.2+

    scrollView.contentInsetAdjustmentBehavior = .never
    
    0 讨论(0)
  • 2021-01-11 10:08

    I found the explanation on this website:

    http://www.codelord.net/2013/10/18/adapting-scroll-views-to-ios-7/

    Handling navigation bar on top of our scroll view

    The iOS 7 view of course comes with the new look where scroll views go under the navigation bar for a nice effect. One can change the scroll view’s contentInset manually to cover for the portion of it that is being overlapped at the top, but doing so manually is tedious and not fun. I was very thrilled to discover handling it should come at no cost if my ViewController has automaticallyAdjustsScrollViewInsets set to YES.

    This didn’t work for me out of the box since it turns out for the magic to happen the scroll view has to be the first subview of your ViewController’s UIView. I had to reorder my subviews and then the magic started rolling.

    0 讨论(0)
  • 2021-01-11 10:25

    It's probably an issue with the view insets.

    On your XIB/Storyboard for your view controller, make sure to uncheck the Adjust Scroll View Insets

    uncheck the Adjust Scroll View Insets

    or in your code add self.automaticallyAdjustsScrollViewInsets = false

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