A clever way to implement the floating tableViewHeader, tableheaderview floating

Source: Internet
Author: User

A clever way to implement the floating tableViewHeader, tableheaderview floating
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 sayCSStickyHeaderFlowLayoutIt 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 gitHubARSegmentPagerInspired 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, so we need to find a way to make the tableView gesture pass through this custom headerView, and this method is to reload the hitTest method of headerView. (The code has been updated to gitHub.) the specific mechanism and principle of hitTest can be google Baidu. The general function is to control the transfer of UIEvent and the view that should be returned to respond to the event. Because the event is passed down from the top layer, the view added to the headerView will first respond to its own event, therefore, subviews such as buttons on headerView will not be affected (but the gestures added to headerView will not work. If necessary, you can add a subView of equal size on headerView, add the gesture to this subView ). Therefore, the hitTest method is useful here ~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.