UIScrollView Not Scrolling?

前端 未结 6 883
无人共我
无人共我 2020-12-16 18:04

I have a UIScrollView created in interface builder with a bunch of UITextView and UIImageView objects already added. I have it connect

6条回答
  •  长情又很酷
    2020-12-16 18:33

    I use a custom view on the UIScrollView, for pull to refresh function, and the scroll view is not scrollable. I try set contentSize with AutoLayout, and try set it by codes too. The scroll view still cannot scroll.

    After spending 3 ~ 4 hours, I solve it by contentInset. It will tell scroll view to add some extra space for scrolling.

    override func viewDidLayoutSubviews() {
        // Add extra 15pt on the `top` of scrollView.
        //self.scrollView.contentInset = UIEdgeInsetsMake(15, 0, 0, 0)
    
        // Add extra 2pt on the `bottom` of scrollView, let it be scrollable. And the UI is more beautiful in my case. 
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 2, 0)
    }
    

    Reference docs:

    • Understanding the contentOffset and contentInset properties of the UIScrollView class @blog
    • What's the UIScrollView contentInset property for? @Stackoverflow

提交回复
热议问题