【发布时间】:2018-12-13 01:41:58
【问题描述】:
我对 IOS 开发非常陌生,所以其中一些可能看起来很明显。我尝试结合customize the user annotation 和marking a place on the map with an image 的示例
我觉得我需要添加以下代码行并以某种方式将此代码附加到第一个链接中描述的用户注释中,但我不知道如何执行此操作。我猜我也可以将其中一些函数插入到 customUserLocationAnnotationView 中,但是没有明显的指示可以将其放置在该类中的哪个位置。
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
var annotationImage = mapView.dequeueReusableAnnotationImage(withIdentifier: "pisa")
if annotationImage == nil {
var image = UIImage(named: "pisavector")!
image = image.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: 0, bottom: image.size.height/2, right: 0))
annotationImage = MGLAnnotationImage(image: image, reuseIdentifier: "pisa")
}
return annotationImage
}
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
编辑
我不只是想将图像放在这样的随机位置
我希望图片以用户标注为中心,当用户移动时,图片也会随之移动,如下图所示
附注
我也收到错误“无法为 ViewController (BYZ-38-tOr) 渲染和更新自动布局状态:代理崩溃 Main.storyboard”,但我认为这并不重要,因为我的程序仍然在模拟器上构建并运行良好。
【问题讨论】:
-
您能分享一下您使用的是哪个版本的 Mapbox Maps SDK?
-
@jmkiley 我不知道什么版本。应该是最近的一个。我只是用 cocoapods 下载的。