step 1 定义图片或地图的高度,创建图片或地图视图
//地图高度 let mapHeight:CGFloat = 200 + STATUS_HEIGHT
let frame = CGRectMake(0,SCREEN_WIDTH,SCREEN_HEIGHT) tableView = UITableView(frame:frame,style:.Grouped ) tableView.backgroundView = UIImageView(image: UIImage(named: "bgImage")) tableView.separatorStyle = .None tableView.delegate = self tableView.dataSource = self self.view.addSubview(tableView) //地图 mapView = MKMapView(frame:CGRectMake(0,-mapHeight,mapHeight)) mapView!.mapType = MKMapType.Standard mapView!.contentMode = .ScaleAspectFill mapView!.clipsToBounds = true tableView.addSubview(self.mapView!) tableView.contentInset = UIEdgeInsetsMake(mapHeight-STATUS_HEIGHT,0)
说明:其中 STATUS_HEIGHT 是状态栏高度
let STATUS_HEIGHT :CGFloat = UIApplication.sharedApplication().statusBarFrame.height
scrollViewDidScroll
step 2 在scrollView 代理方法scrollViewDidScroll 中处理下拉发生的变化
//地图下拉放大 func scrollViewDidScroll(scrollView: UIScrollView) { let offsetY = scrollView.contentOffset.y let radius = -offsetY/mapHeight if(-offsetY > mapHeight){ mapView.transform = CGAffineTransformScale(CGAffineTransformIdentity,radius,radius) var frame = mapView.frame frame.origin.y = offsetY mapView.frame = frame } }
去掉这一句
mapView.transform = CGAffineTransformScale(CGAffineTransformIdentity,radius)
加上这一句
frame.size.height = -offsetY原文链接:/swift/322789.html