简体   繁体   English

自定义scrollView滚动时,移动标题视图

[英]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.

相关问题 滚动UICollectionView时如何在顶部屏幕上自定义标题视图? - How to custom header view that sticky in top screen when scroll UICollectionView? 滚动时Phonegap Applicatin标头移动 - Phonegap Applicatin header move when scroll 当单元格被DatePicker隐藏时移动滚动视图 - Move scroll view when cell hidden by the DatePicker 出现键盘时移动视图,并将其显示在scrollView中。 迅捷3 - Move View when keyboard appears and present it in a scrollView. Swift 3 UIScroll view内的UITableview-触摸tableview时禁用scrollview滚动 - UITableview inside UIScroll view - Disable scroll of scrollview when touching tableview 将子视图添加到视图控制器时,ScrollView不滚动 - ScrollView doesn't scroll when added a subview to a view controller 在视图加载时滚动到滚动视图中选定的 position - SwiftUI - Scroll to selected position in scrollview when view loads - SwiftUI 当我在TabBarController中切换视图时,ScrollView停止滚动,如何解决? - When i switch View In TabBarController the ScrollView Stop Scroll,How to Solve it? 滚动视图滚动时如何检查视图可滚动位置 - How to check view scrollable position when scrollview scroll 折叠标题视图 - ScrollView 在到达底部时停止滚动 - Collapsing header view - ScrollView stops scrolling when it reaches bottom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM