iOS:如何滚动导航栏作为视图控制器滚动
我想在用户在视图控制器上滚动时滚动导航栏。这应该类似于YouTube应用程序的主页运行方式。当用户向下滚动时,应使导航栏可见。导航栏应移动到滚动量。
我知道HIDESBARONSWIPE
和setNavigationbarhidden
,但是这些并不能准确控制y轴。我还读到Apple不支持直接修改导航杆框架。
那么,YouTube如何做到这一点?我正在寻找一个MVP,展示导航栏位置更改以及uiscrollview
偏移更改。
I want to scroll the navigation bar as the user scrolls on the view controller. This should be similar to how the YouTube app's home page is working. When the user scrolls down, the navigation bar should be made visible. The navigation bar should move as much as the scroll amount.
I'm aware of hidesBarOnSwipe
and setNavigationBarHidden
, but these do not give precise control of the y-axis. I'm also reading that Apple does not support directly modifying the navigation bar frame.
So, how does YouTube do this? I'm looking for an MVP demonstrating navigation bar position change along with a UIScrollView
offset change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想做什么,我将做出一些猜测。
首先,YouTube应用程序主页的顶部几乎可以肯定是 不是 a
uinavigationbar
- 它的行为不像一个推动/弹出控制器正在进行,它在标签栏控制器设置等中。因此,假设它是带有子视图的视图 - 我们将其称为“滑动标头视图” - 您的目标是:
我们可以通过将标头视图的顶部限制到滚动视图的框架布局指南的顶部来完成此操作。
.contentoffset.y
.constant
值,以将标题视图移动,.constant
标题查看以下是从开始的样子:
nofollow noreferrer”>
我们向上滚动:
当我们向下滚动一点时:
我们向下滚动后:
这是该示例代码:
简单的两标签“标头”标头“ “查看
示例查看控制器
所有内容都是通过代码完成的 -
@iboutlet
或@ibaction
需要连接。Without additional detail about what you want to do, I'll make some guesses.
First, the top of the YouTube app's home page is almost certainly not a
UINavigationBar
-- it doesn't behave like one, there is no pushing/popping of controllers going on, it's in a tab bar controller setup, etc.So, let's assume it's a view with subviews - we'll call it a "sliding header view" - and your goal is:
We can accomplish this by constraining the Top of that header view to the Top of the scroll view's Frame Layout Guide.
.contentOffset.y
.constant
value to move the header view up.constant
value to move the header view downHere's how it will look at the start:
as we scroll up just a little:
after we've scrolled up farther:
as we scroll down just a little:
after we've scrolled down farther:
Here's the example code for that:
Simple two-label "header" view
example view controller
Everything is done via code - no
@IBOutlet
or@IBAction
connections needed.