UITableView浮动视图,如iPhone地图应用 [英] UITableView floating view like iPhone Maps app
问题描述
在iOS 6地图应用程式中,当查看位置的详细资料时,会有一个控制项,例如 UISegmentedControl
。它有3个标签:'信息','评论'和'照片'。
In the iOS 6 Maps App, when looking at the details for a location, there is a control that acts like a UISegmentedControl
. It has 3 "tabs": 'Info', 'Reviews', and 'Photos'.
此控件在图片可见时会向上和向下滚动,到屏幕的顶部,并向下滚动更多时浮动。这些照片可能有助于澄清我要陈述的内容:
This control scrolls up and down when the picture is visible, but becomes anchored to the top of the screen and floats when scrolling down more. These pictures may help clarify what I'm trying to state:
有关如何在自己的UITableView上创建此行为的任何提示? tableview需要是 Grouped
样式,我需要有多个部分,因此使用Section Header View是不成问题的。
Any tips on how I can create this behavior on my own UITableView? The tableview needs to be of the Grouped
style, and I need to have multiple sections, so using the Section Header View is out of the question.
推荐答案
使用 UITableView的tableHeaderView
属性添加分段控件。
make use of the UITableView's tableHeaderView
property to add your segmented control.
MapView
和 TableView
应为兄弟,并作为子视图添加到scrollView
MapView
and TableView
should be siblings, and added as a subviews to a scrollView.
tableView.frame.size.height
应该是你在image2(parentViewHeight-navBarHeight)
The tableView.frame.size.height
should be what you see in the image2 (parentViewHeight-navBarHeight)
scrollView.frame.size.height = tableView.frame.size.height
scrollView.contentSize.height = tableView.frame.size.height + mapView.frame.size.height
足以获得你想要做的效果。让我知道如果你有任何问题。
this should be enough to get the effect you are trying to do. let me know if you have any issues with it.
PS:mapView只是一个占位符,我假设你在分段控件上方看到的视图。你可以用任何你想要的视图来替换它。我假设你知道如何做这些视图的分组tableView部分。
PS: mapView is just a place holder I assumed for the view you see above the segmented control. you can replace it with any view you want. I am assuming you know how to do the grouped tableView part of these views.
这篇关于UITableView浮动视图,如iPhone地图应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!