【发布时间】:2016-11-03 10:39:08
【问题描述】:
我正在使用 MapKit,我目前正在尝试在我的引脚上设置自定义引脚注释图像。但是,我很难弄清楚为什么它不起作用。所有其他代码都运行良好,当我在设置后尝试打印图像的框架时,它确实显示了我的“pinImage”的正确尺寸,因此它似乎能够在属性上设置图像。
此外,代理设置正确,这是通过在默认引脚上设置自定义颜色来验证的。
我也尝试过使用“pinImage.png”,但没有成功。而且由于 MKPinAnnotationView 是 MKAnnotationView 的子类,我认为这应该是问题的原因没有问题,并且可以肯定的是,我也尝试使用 MKAnnotationView,但没有运气。
这是我的代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Pin {
let identifier = LocalConstants.pinIdentifier
var view: MKPinAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
let detailButton = UIButton(type: .detailDisclosure) as UIView
view.rightCalloutAccessoryView = detailButton
//view.pinTintColor = Util.Colors.pluppPurple
}
view.image = UIImage(named: "pinImage")
return view
}
提前致谢!
【问题讨论】:
标签: swift mapkit swift3 mkannotationview mkpinannotationview