问题描述
我在 iOS 8 下实现 UIRefreshControl 时遇到了一种闪烁.每次我第一次来到 tableView 的顶部时(意味着应用程序刚刚启动时),我都会看到下面的 gif 中显示的闪烁.在此视图再次加载之前,在我到达 tableView 顶部的任何后续时间都不会发生这种情况,因此在我在应用程序的另一个视图中执行某些操作或完全重新启动它之后.
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.
这是我的应用程序的 viewDidLoad() 中的代码:
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)
}
refreshControl 是在 viewDidLoad() 函数之外声明的,因为我想从我的 updateData() 函数中调用 endRefreshing 方法.这似乎是显而易见的方法.
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.
推荐答案
我能够通过更改以下行来解决此问题
I was able to resolve this by changing the following line
tableView.addSubview(refreshControl)
到
tableView.insertSubview(refreshControl, atIndex: 0)
感谢这条评论:没有 UITableViewController 的 UIRefreshControl
这篇关于UIRefreshControl 闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!