【发布时间】:2018-01-09 01:57:11
【问题描述】:
当在 MapView 中自定义我的注释视图 (Pin) 时,我需要在我的注释的白色边框 OUT 中。
我也需要在阴影中,点击时。但我怎么能做到呢? (当我取消选择注释时必须保持正确的样式)。如果我做到了:
var newFrame: CGRect = view.frame; newFrame = newFrame.insetBy(dx: -borderWidth, dy: -borderWidth); view.frame = newFrame;在 mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) 方法中并设置边框 - 我的图像也会放大,但它不正确。
// My custom annotation
class CustomPointAnnotation: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var restoInfo: Restaurant?
init(resto: Restaurant) {
self.coordinate = resto.coordinate!
self.restoInfo = resto
}
}
// And func adding custom annotation on MapView
var restorationPin: CustomPointAnnotation!
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
let cpa = annotation as? CustomPointAnnotation
if cpa?.restoInfo == nil {
return nil
}
let annotationView = MKAnnotationView(annotation: restorationPin, reuseIdentifier: "id")
let icon = cpa?.restoInfo?.encodeBase64toImage(base64: (cpa?.restoInfo?.logoMap)!)
annotationView.image = icon
annotationView.layer.masksToBounds = true
annotationView.contentMode = .scaleAspectFill
annotationView.frame.size = CGSize(width: 45, height: 45)
annotationView.layer.cornerRadius = 22.5
return annotationView
}
【问题讨论】:
-
您是否查看了来自
MKMapViewDelegate的 mapViewdidSelect和didDeselectMKAnnotationView 方法? -
现在是空的。我不知道怎么做:(
标签: ios swift mapkit geometry mkannotationview