【发布时间】:2015-05-16 10:35:57
【问题描述】:
我正在尝试在UITableView 上创建一个不断增长的UITableViewHeader。我在 UITableView 的 tableHeaderView 中设置了一个 UITableView 和一个 mapView。
tblView.bounces = true
tblView.bouncesZoom = true
tblView.alwaysBounceVertical = true
mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, CGFloat(kMapHeaderHeight))
mapView.mapType = MKMapType.Standard
mapView.zoomEnabled=true
mapView.scrollEnabled = true
mapView.delegate = mapHelper
tblView.tableHeaderView = mapView
并且还实现了scrollViewDidScroll委托,每当它向下滚动时,我都会将headerview的框架更改为
func scrollViewDidScroll(scrollView: UIScrollView) {
var scrollOffset = scrollView.contentOffset.y
println("\(scrollOffset)")
var headerFrame : CGRect = self.mapView.frame
if (scrollOffset < 0){
headerFrame.size.height -= scrollView.contentOffset.y/3
}
self.mapView.frame = headerFrame
}
但是,如果没有弹跳,它不会像预期的那样增长。看起来很不清楚。有什么帮助吗?
当下拉为 UITableVIew header without bouncing when pull down , Expand UITableView Header View to Bounce Area When Pulling Down
这是项目的链接: https://drive.google.com/file/d/0B6dTvD1JbkgBVENUS1ROMzI0Wnc/vie
已编辑:我以某种方式设法产生了效果,但动画似乎很慢
func scrollViewDidScroll(scrollView: UIScrollView) {
let yPos: CGFloat = -scrollView.contentOffset.y
if (yPos > 0) {
var mapViewRect: CGRect = self.mapView.frame
mapViewRect.origin.y = scrollView.contentOffset.y
mapViewRect.size.height = kHeaderHeight+yPos
self.mapView.frame = mapViewRect
}
}
let kHeaderHeight:CGFloat = 200
【问题讨论】:
-
我尝试了和你一样的方法,但是我无法更改 headerView 的大小。但是按照这个thinkandbuild.it/implementing-the-twitter-ios-app-ui 教程,我确实做到了。
-
谢谢..但不知道如何实现它..您可以将其发布为答案
标签: ios uitableview swift uiscrollview mkmapview