【发布时间】:2015-04-18 02:56:21
【问题描述】:
我正在尝试使用 swift 创建一个 iOS 应用程序,该应用程序在地图视图上创建注释。但是,在大多数情况下,我都在尝试创建一个自定义视图,当用户点击图钉时会弹出该视图。这是放置注释的代码:
let point = MKPointAnnotation()
//This isn't the actual location
let location = CLLocationCoordinate2DMake(1, 1)
point.coordinate = location
point.title = "Title"
point.subtitle = "Description"
map.addAnnotation(point)
map.centerCoordinate = point.coordinate
let mapCamera = MKMapCamera()
mapCamera.centerCoordinate = location
mapCamera.altitude = 300
mapCamera.heading = 180
self.map.camera = mapCamera
此代码将图钉放置在正确的位置。但是,假设我有一个红色背景的 MKAnnotationView 对象,如下所示:
let pointDesc = MKAnnotationView()
pointDesc.backgroundColor = UIColor.redColor()
如何将该视图添加到 MKPointAnnotation。最初我认为map.addSubview(pointDesc) 会起作用。但事实并非如此。
有人有什么建议吗?
【问题讨论】:
标签: ios swift maps mkannotationview