0

我正在尝试使用用户图片实现注释,它可以工作,但是随后,点击注释识别停止工作。

如何将子视图点击委派给地图?

这是我的覆盖功能

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
    }
}
4

0 回答 0