【问题标题】:UIRefreshControl layout wrong in UIScrollView with left/right contentInsetUIScrollView 中的 UIRefreshControl 布局错误,左/右 contentInset
【发布时间】:2018-01-09 23:20:12
【问题描述】:

如果我使用具有非零左/右 contentInsetUIScrollView 并添加 UIRefreshControl,则刷新位置不正确,使 UI 和动画看起来很奇怪。

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

我不想修改刷新控件的布局,但找不到正确定位的方法。

这是错误的屏幕截图:

这是来自视图检查器的动画:

【问题讨论】:

  • 如果控制台上没有约束错误,会不会是滚动视图上缺少一个?看起来像 refreshControl 保持故事板大小。
  • 那里也有细胞吗?因为它看起来可能会偏离视图的右侧。你能取消视图以确保滚动视图正确定位吗?调试代码层次结构底部的图标之一就是这样做的。
  • @EricD 这个演示使用的是自动布局,但我可以使用普通的框架数学来重现它。
  • @KyleBashour 在滚动视图中没有子视图 :(
  • 啊,我的错。奇怪的是 UIRefreshControl 文档仍然有警告developer.apple.com/documentation/uikit/uirefreshcontrol

标签: uitableview uiscrollview uicollectionview uikit uirefreshcontrol


【解决方案1】:

我通过创建 UIRefreshControl 子类在本地修复它,但这绝对是一个 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
    }
}

我将提交雷达,因为我开始认为这是 UIKit 中的一个错误。

【讨论】:

  • 既然刷新控件是滚动视图的子视图,我其实觉得你并不关心滚动视图的框架:newFrame.origin.x = -superScrollView.contentInset.left
  • 在我看来会更好:newFrame.origin.y = newValue.minY - (superScrollView.contentInset.top / 2)
猜你喜欢
  • 2018-12-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2018-05-17
  • 2017-01-20
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
相关资源
最近更新 更多