Embed a sticky title in e.g. a UITableView

I would like to have an idea that scrolls. The view will have a title that initially takes up about a third of the screen. While the user scrolls, the title will begin to exit the screen, but as soon as about 50 pixels remain, I would like the title to be inserted and the rest of the screen to scroll anyway ... Any idea would be useful, I’m more detailed about the methods than the actual the code. Here is a visual representation of what I'm trying to do in ascii:

+-------------+ +-------------+ +-------------+ +-------------+ +-------------+ | ### | | ## | | # | | # | | # | | ## | | # | |-------------| |-------------| |-------------| | # | |-------------| | 1. Lorem | | 2. Lorem | | 3. Lorem | |-------------| | 1. Lorem | | 2. Lorem | | 3. Lorem | | 4. Lorem | | 1. Lorem | | 2. Lorem | | 3. Lorem | | 4. Lorem | | 5. Lorem | | 2. Lorem | | 3. Lorem | | 4. Lorem | | 5. Lorem | | 6. Lorem | | 3. Lorem | | 4. Lorem | | 5. Lorem | | 6. Lorem | | 7. Lorem | | 4. Lorem | | 5. Lorem | | 6. Lorem | | 7. Lorem | | 8. Lorem | | 5. Lorem | | 6. Lorem | | 7. Lorem | | 8. Lorem | | 9. Lorem | | 6. Lorem | | 7. Lorem | | 8. Lorem | | 9. Lorem | | A. Lorem | | 7. Lorem | | 8. Lorem | | 9. Lorem | | A. Lorem | | B. Lorem | +-------------+ +-------------+ +-------------+ +-------------+ +-------------+ 
+4
source share
1 answer

In scrollViewDelegate , implement scrollViewDidScroll: and re-set the center property of your section title to something like:

 myHeader.center = CGPointMake(myHeader.center.x, myHeader.center.y - scrollView.contentOffset.y); 

when you determine that myHeader.frame.origin.y <= -scrollView.contentOffset.y

This is from the head, but should point you in the right direction.

+1
source

Source: https://habr.com/ru/post/1392608/


All Articles