I would like to have a view that scrolls. The view would have a header, which would initially take about a third of the screen. While the user scrolls, the header will start to get off screen, but once there is about 50px left, I would like the header to stick and the rest of the screen would still scroll… Any idea would be helpful, I’m more looking about methods than actual code. Here is an ascii art representation of what I’m trying to do :
+-------------+ +-------------+ +-------------+ +-------------+ +-------------+
| ### | | ## | | # | | # | | # |
| ## | | # | |-------------| |-------------| |-------------|
| # | |-------------| | 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 |
+-------------+ +-------------+ +-------------+ +-------------+ +-------------+
In your
scrollViewDelegate, implementscrollViewDidScroll:and re-set thecenterproperty of your section header to something like:whenever you determine that
myHeader.frame.origin.y <= -scrollView.contentOffset.yThis is off the top of my head, but should point you in the right direction.