[英]Custom scrollView when Scroll, move header view
I have an question, like this photo User Profile View 我有一个问题,像这张照片的用户个人资料视图
In Apple document, they say not add UITableView to UIScrollView, but now i needs to do this..? 在Apple文档中,他们说不将UITableView添加到UIScrollView,但是现在我需要这样做。 is someone have an good idea ?
有人有个好主意吗?
Thank you 谢谢
The problem is kind of complex. 这个问题有点复杂。 There are different ways to solve that and none of them is easy.
有多种解决方法,但都不容易。
You can add a table view inside a scrollview (nested techniques), but if you try to scroll it won't feel natural. 您可以在滚动视图内添加表格视图(嵌套技术),但是如果尝试滚动,则感觉不自然。 To improve that user experience you need to implement scrollview delegate methods and apply some inner logic.
为了改善用户体验,您需要实现滚动视图委托方法并应用一些内部逻辑。 All this kind of techniques are explained in two wwdc 2013-14 videos here and here , but I strongly suggest you to watch also earlier sessions of 2011-12 to unleash the power of scrollviews.
所有这两种技术都在此处和此处的两个wwdc 2013-14视频中进行了说明,但我强烈建议您也观看2011-12的早期会议,以释放滚动视图的功能。
The best way is to implement a UICollectionView
with a custom layout, this is also explained in Advanced collection view user interfaces from wwdc 2014, in these session Apple explain how they developed AppStore application that contains a floating header. 最好的方法是使用自定义布局实现
UICollectionView
,wwdc 2014的“ 高级集合视图”用户界面中也对此进行了说明,Apple在这些会议中解释了他们如何开发包含浮动标头的AppStore应用程序。
Another solution is search on github, you can find CSSStickyHeaderFlowLayout or similar solutions. 另一个解决方案是在github上搜索,您可以找到CSSStickyHeaderFlowLayout或类似的解决方案。
The last one can be applied if you just need to add a header to a scrollview (without nesting another scrollview) just using auto layout. 如果只需要使用自动布局将标题添加到滚动视图(不嵌套另一个滚动视图),则可以应用最后一个。
The layout image which you have attached, its kind of paralax control. 您已附加的布局图像,其一种视差控件。
I had some kind of layout earlier and configured easily with. 我之前有一些布局,可以轻松配置。
https://github.com/Vinodh-G/ParallaxTableViewHeader https://github.com/Vinodh-G/ParallaxTableViewHeader
let headerView : ParallaxHeaderView = ParallaxHeaderView.parallaxHeaderViewWithImage(UIImage(named: ""), forSize: CGSizeMake(self.tableview.frame.size.height, headerHeight)) as! ParallaxHeaderView
self.tableview.tableHeaderView = headerView
func scrollViewDidScroll(scrollView: UIScrollView) {
let header: ParallaxHeaderView = self.tabkeview.tableHeaderView as! ParallaxHeaderView
header.layoutHeaderViewForScrollViewOffset(scrollView.contentOffset)
self.tableview.tableHeaderView = header
}
I dont know any swift custom library , but conceptually I think you can do it with a floating header view. 我不知道任何快速的自定义库,但是从概念上讲,我认为您可以使用浮动标头视图来实现。 I know 2 project in obectiveC you can bridge in your swift project:
我知道obectiveC中的2个项目可以在您的swift项目中进行桥接:
Both project, after you add this custom header view in your table, customize the scroll delegate methods, and you can override these methods for your personal pourpose. 将两个自定义标题视图添加到表中之后,这两个项目都将自定义滚动委托方法,并且可以出于个人目的重写这些方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.