当 UIScrollView 滚动时使静态 UIView 粘滞 [英] Make static UIView sticky when UIScrollView is scrolling

查看:23
本文介绍了当 UIScrollView 滚动时使静态 UIView 粘滞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我有一个比设备高度长得多的滚动视图(图表:文字)
  • 滚动视图底部是一些具有不同背景颜色的底部内容(图表:法国媒体).
  • 为了将底部内容与文字分开,我创建了一个 1pt 高的 UIView 作为边框(图表:红线)
  • 我有一个按钮位于设备底部,在滚动视图之外(滚动视图是 device.height - button.height).此按钮的背景颜色与底部内容的背景颜色相匹配.
  • I've got a scroll view (diagram: words) that is much longer than the device height
  • At the bottom of the scroll view is some bottom content (diagram: french press) with a different background colour.
  • To separate the bottom content from the words, I've created a 1pt high UIView to act as a border (diagram: red line)
  • I have a button that sits on the bottom of the device, outside the scroll view (the scroll view is device.height - button.height). This button's background colour matches the bottom content's background colour.

如果没有将底部按钮与内容视图分开,不同的背景颜色看起来很不稳定,因此虽然底部内容不可见,但我希望边框具有粘性,并且看起来位于底部按钮上方(图:红线).

The different background colours look pretty wonky without something separating the bottom button from the content view, so while the bottom content is NOT visible, I'd like the border to be sticky, and appear to be sitting above the bottom button (diagram: red line).

小提示:我在 IB 中使用 AutoLayout,但我为边框约束创建了一个 IBOutlet,我可以在代码中轻松操作它.

A small note: I'm using AutoLayout in IB, but I have an IBOutlet created for the border constraint that I can easily manipulate in code.

推荐答案

这是一个可以完成这项工作的库:https://github.com/ericcastro/ECStretchableHeaderView

Here is a lib that does the job: https://github.com/ericcastro/ECStretchableHeaderView

(它与示例中的 UItableView 一起使用,但实现基于 UIScrollview)

(it works with UItableView in the sample but implementation is based on UIScrollview)

您必须通过更改逻辑来更新代码:这里视图在顶部,但整个原理都在那里!

You have to update the code by changing the logic: Here the view is on the top, but the whole principle is there!

这篇关于当 UIScrollView 滚动时使静态 UIView 粘滞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆