自定义UIRefreshControl内容未逐渐显示



我创建了一个自定义视图,并将其作为子视图添加到滚动视图的刷新控件中,如下所示:

private func configureRefreshControl() {
scrollView.refreshControl = UIRefreshControl()
let refreshContents = BaseRefreshControl.loadFromNib()
refreshContents.frame = scrollView.refreshControl!.bounds
self.refreshControl = refreshContents
scrollView.refreshControl?.tintColor = .clear
scrollView.refreshControl?.backgroundColor = .blue
scrollView.refreshControl?.addSubview(refreshContents)
}

我的BaseRefreshControl基本上是一个.xib文件,包含一个UIView和一个以该UIView为中心的UILabel。

正如您所知,当您下拉滚动视图以刷新内容时,它会逐渐打开(很像慢速动画(。然而,我发现奇怪的是,每当我下拉刷新时,我的UILabel都会在UIView的中心部分显示之前显示出来。

如果可以的话,我有这样的东西:

---------------------------
--                       --
-- --------------------- --
--       MyLabel         --
--                       --

上半部分是我的UIRefreshControl,它已经逐渐开始显示。"MyLabel"在下面显示并重叠视图控制器的元素。我希望标签仅在UIRefreshControl的该部分显示时显示,仅在UIView完全显示时显示。

看起来解决方案很简单:

scrollView.refreshControl?.clipsToBounds = true

希望这对将来的人有所帮助!

最新更新