A clever way to implement the floating tableViewHeader, table border
Previously, we had to implement a similar floating + parallax headerView because of our work. After studying how to do this for a long time, we finally used UICollectionView +
CSStickyHeaderFlowLayout(I have to say
CSStickyHeaderFlowLayoutIt is really a very powerful library, and the author's understanding of UICollectionView is really profound, it is recommended that you have a look at his source code when you are free ). I used a UICollectionView to implement a UITableView... Later, on gitHub
ARSegmentPagerInspired by this, I found another clever way of thinking. It can also achieve this effect better, and it can be achieved with UITableView. The implementation method is also relatively simple, and more extensions can be made, so record it. The core of this idea is to place the custom headerView on the tabView instead of tableView. tableHeaderView (both headerView and tableView are added to the view of viewController), and set the contentInset of tableView as the appropriate value. When the tableView slides, dynamically change the position or size of the view to make the headerView look like a tableView with the floating function. tableHeaderView. I used to think about how to use tableView to implement this function. This method made me jump out of the mindset and put headerView outside, but how can I change it !!! (If you don't say it in advance, you can hardly see that this is not tableHeaderView.) For example: Or: Of course, you can do more cool effects, here are just a few of the simplest and easiest implementations. The specific demo address here: After playing https://github.com/Phelthas/TEST_XMLCommon you may also find the problem, this only when the finger on the tableView to slide, on the headerView will not work ...... This cannot be tolerated. What I think of now is that we can use the hitTest method to pass the gesture through headerView. However, we have no time to try it now. If we are free on weekends, we can try again ~~