Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRefreshControl layout wrong in UIScrollView with left/right contentInset

If I'm using a UIScrollView with a non-zero left/right contentInset and add a UIRefreshControl, the refresh is positioned incorrectly making the UI and animation look bizarre.

scrollView.contentInset = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40)
scrollView.refreshControl = UIRefreshControl()

I'd prefer not to hack the layout of the refresh control, but can't find a way to get this to position correctly.

Here's a screenshot of the bug: enter image description here

And here's an animation from the view inspector:

enter image description here

like image 750
rnystrom Avatar asked Jan 09 '18 23:01

rnystrom


1 Answers

I fixed it locally by creating a UIRefreshControl subclass, but this is definitely a hack.

override var frame: CGRect {
    get { return super.frame }
    set {
        var newFrame = newValue
        if let superScrollView = superview as? UIScrollView {
            newFrame.origin.x = superScrollView.frame.minX - superScrollView.contentInset.left
        }
        super.frame = newFrame
    }
}

I'll file a radar since I'm starting to think this is a bug in UIKit.

like image 155
rnystrom Avatar answered Sep 23 '22 18:09

rnystrom