I'd like to replicate the sticky behavior of the search bar in the iPhone Contacts app.
When the user scrolls the view down, the search bar also comes down along with the view:
If the user scrolls up, the table scrolls accordingly, with the following two behaviors:
(1) the search bar remains fixed at the top, and
(2) the subsequent section header stops appropriately below the search bar:
When the next section header comes, the previous header disappears below the search bar:
Note: the section index control (a-z on the right hand side) appears on top of the search bar as well. Ergo, fiddling with the contentInset
will push the section index control down along with it.
I've created a custom UIViewController
, added a UITableView
, set its contentInset
to the height of the search bar. I created a UIView
, added the search bar as its subview, and then added the UIView
to the UITableView
. However, as noted above, when the user is scrolling, the section headers still stick at the y-position zero, and not at the header height. Additionally, the section header index control position is adversely affected.
I'd appreciate a solution to this problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…