Offsetting UIRefreshControl

前端 未结 9 1526
醉话见心
醉话见心 2020-12-14 01:14

I am currently using a JASidePanel for my application and I have a UITableViewcontroller with a UIRefreshControl as one of the ViewControllers for it. The width of my tablev

9条回答
  •  情深已故
    2020-12-14 01:50

    Here's a Swift version similar to the workaround that Werewolf suggested. I'm using my own custom activity view class (MyCustomActivityIndicatorView) and it's also a subview of the refresh control, so I make sure I don't mess with it's frame, just the frame of the default subviews. After calling layoutSubviews on super I adjust the custom activity view's frame to match. This is all contained in a custom UIRefreshControl subclass.

    override func layoutSubviews() {
    
        for view in subviews {
            if view is MyCustomActivityIndicatorView {
                continue
            } else {
                // UIRefreshControl sizes itself based on the size of it's subviews. Since you can't remove the default refresh indicator, we modify it's frame to match our activity indicator before calling layoutSubviews on super
                var subFrame = view.frame
                subFrame.size = activityView.intrinsicContentSize()
    
                // add some margins
                subFrame.offsetInPlace(dx: -layoutMargins.left, dy: -layoutMargins.top)
                subFrame.insetInPlace(dx: -(layoutMargins.left+layoutMargins.right), dy: -(layoutMargins.top+layoutMargins.bottom))
    
                view.frame = subFrame.integral
            }
        }
    
        super.layoutSubviews()
    
        activityView.frame = bounds
    }
    

    Note: I'm adding in UIView's layout margins in which isn't strictly necessary but gives my activity indicator some space to breath.

提交回复
热议问题