ilyi1116
ilyi1116

Reputation: 101

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..? is someone have an good idea ?

Thank you

Upvotes: 2

Views: 2741

Answers (3)

Hasya
Hasya

Reputation: 9898

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

 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



}

Upvotes: 1

Andrea
Andrea

Reputation: 26383

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.
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.
Another solution is search on github, you can find CSSStickyHeaderFlowLayout or similar solutions.
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.

Upvotes: 2

Alessandro Ornano
Alessandro Ornano

Reputation: 35412

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:

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.

Upvotes: 0

Related Questions