问题描述
我正在构建一个包含社交内容流的应用程序,并且我正试图了解Instagram在应用程序中的流程。所以基本上是一个顶部标题,滚动屏幕,但在内容和内容之间反弹。我可以让顶部标题滚动离开屏幕,我可以让视图不反弹,但我想使用Pull来刷新,最后会在faux导航栏上方 UIView
。我知道一个普通的Navbar会产生这个但是这个滚动的是一个不同的故事。
I am building an app with a stream of social content and am trying to get the behavior of how instagram does it's stream in app. So basically a top header that scrolls off the screen but bounces between that and the content. I can make the top header scroll off the screen and I can make the view not bounce but I want to use Pull to refresh and that ends up going above the "faux" nav bar UIView
. I know that a normal Navbar will produce this but this one that scrolls off is a different story.
目前我有一个 UITableview
在 UITableViewCell
之上有一个 UIView
,一切都很好,除了反弹发生在<$ c $之上C>的UIView 。我想我需要在 UITableView
之上获得 UIView
但是在UITableViewController中,故事板不允许我放置 UITiew
上方的 UIView
。
Currently I have a UITableview
that has a UIView
above the UITableViewCell
and everything works great except the bounce happens above the UIView
. I figure I need to get the UIView
above the UITableView
however in the UITableViewController the storyboard won't allow me to place the UIView
above the UITableView
.
任何想法???
谢谢
推荐答案
好吧,我终于把这一切都搞定了,所以我想我会为每个人发布答案。
Well I finally got this all to work so I thought I would post the Answer for everyone.
基本上我设定了一个标准导航栏然后在 scrollViewDidScroll
我得到滚动的偏移量并根据它改变帧。这似乎工作得很好,请参阅下面的scrollViewDidScroll方法。
Basically I set a standard Navigation bar and then on scrollViewDidScroll
I get the offset of the scrolling and change the frame based on that. This seems to work perfectly, see below for my scrollViewDidScroll method.
- (void)scrollViewDidScroll:(UIScrollView *)sender {
//Initializing the views and the new frame sizes.
UINavigationBar *navbar = self.navigationController.navigationBar;
UIView *tableView = self.view;
CGRect navBarFrame = self.navigationController.navigationBar.frame;
CGRect tableFrame = self.view.frame;
//changing the origin.y based on the current scroll view.
//Adding +20 for the Status Bar since the offset is tied into that.
navBarFrame.origin.y = MIN(0, (sender.contentOffset.y * -1)) +20;
navbar.frame = navBarFrame;
tableFrame.origin.y = MIN(0,MAX(-44,(sender.contentOffset.y * -1)));
tableView.frame = tableFrame;
}
此外,您还需要让TableView 44px更高来补偿滚动否则你的框架将不够大。我刚刚在viewWillAppear中做了这个并使框架更大。
Also you will want to make your TableView 44px taller to compensate for the scrolling otherwise your frame will not be big enough. I just did this in viewWillAppear and made the frame bigger.
这篇关于如何设置我的iOS故事板像Instagram流一样反弹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!