我尝试使用用户图片实现注释,但它可以正常工作,但是,点击注释识别就会停止工作。
如何将子视图点按到地图?
这是我的覆盖功能
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKindOfClass(MKUserLocation) {
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil
{
let imgUserPic: UIImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
if (userPic != nil) {
imgUserPic.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin.intersect(UIViewAutoresizing.FlexibleHeight).intersect(UIViewAutoresizing.FlexibleRightMargin).intersect(UIViewAutoresizing.FlexibleLeftMargin).intersect(UIViewAutoresizing.FlexibleTopMargin).intersect(UIViewAutoresizing.FlexibleWidth)
imgUserPic.contentMode = UIViewContentMode.ScaleAspectFill
imgUserPic.layer.cornerRadius = 30
imgUserPic.layer.masksToBounds = true
imgUserPic.layer.borderColor = UIColor.whiteColor().CGColor
imgUserPic.layer.borderWidth = 1.0
imgUserPic.image = userPic
imgUserPic.userInteractionEnabled = true
let info: MKPointAnnotation = MKPointAnnotation()
info.title = NSLocalizedString("MYLOCATION", comment: "")
info.coordinate = annotation.coordinate
anView = MKAnnotationView(annotation: info, reuseIdentifier: reuseId)
anView?.addSubview(imgUserPic)
anView?.calloutOffset = CGPointMake(0, 32)
anView!.canShowCallout = true
}
} else {
anView?.annotation = annotation
}
return anView
} else {
return nil
}
}