UIRefreshControl flicker

佐手、 提交于 2020-01-25 00:41:06

问题


I'm experiencing a kind of flicker with my implementation of UIRefreshControl under iOS 8. Every first time I come to the top of my tableView (meaning when the app has just started) I see the flicker shown in the gif below. This does not happen on any subsequent times I come to the top of the tableView until this view is loaded again, so after I did something in another view of the app or restart it altogether.

This is the code in the viewDidLoad() of my application:

let refreshControl = UIRefreshControl()

override func viewDidLoad() {
    super.viewDidLoad()

    // Doing this here to prevent the UIRefreshControl sometimes looking messed up when waking the app
    self.refreshControl.endRefreshing()

    updateData()

    refreshControl.backgroundColor = UIColor(hue: 0.58, saturation: 1.0, brightness: 0.43, alpha: 1.0)
    refreshControl.tintColor = UIColor.whiteColor()
    refreshControl.addTarget(self, action: "updateData", forControlEvents: UIControlEvents.ValueChanged)
    tableView.addSubview(refreshControl)
}

The refreshControl is declared outside of the viewDidLoad() function as I want to call the endRefreshing method from within my updateData() function. This seemed like the obvious way of doing that.


回答1:


I was able to resolve this by changing the following line

tableView.addSubview(refreshControl)

to

tableView.insertSubview(refreshControl, atIndex: 0)

Thanks to this comment: UIRefreshControl without UITableViewController




回答2:


Change the background color of the UIRefreshControl's parent view to be the same as the background color of the UIRefreshControl.

Something like:

refreshControl.Superview.BackgroundColor = refreshControl.BackgroundColor



来源:https://stackoverflow.com/questions/29085003/uirefreshcontrol-flicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!