2014-11-03 3 views
0

이미지 서브 뷰가 MKAnnotationView입니다.MKAnnotationView의 하위보기에있는 UITapGestureRecognizer가 작동하지 않습니다. SWIFT

나는 그에게 UITapGestureRecognizer를 추가하려고했지만 응답이 없다

var tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "annotationClicked:")      
       imageView.userInteractionEnabled = true 
       imageView.addGestureRecognizer(tapGestureRecognizer) 
       pinView.addSubview(imageView) 
       pinView.bringSubviewToFront(imageView) 

나는

답변

1

가 주석 뷰의 탭 (에 반응하는 이유를 몰라 두려워 leftCalloutAccessoryView 또는 rightCalloutAccessoryView) 당신은 UIControl의 자손으로 뷰를 생성해야합니다. 그런 다음 MKMapViewDelegate 프로토콜의 calloutAccessoryControlTapped 메서드를 구현할 수 있습니다. 제스처 인식기를 사용할 필요가 없습니다.

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { 
    if annotation is PinAnnotation { 
     let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin") 

     pinAnnotationView.pinColor = .Purple 
     pinAnnotationView.draggable = true 
     pinAnnotationView.canShowCallout = true 
     pinAnnotationView.animatesDrop = true 

     // button as callout accessory 
     let deleteButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton 
     deleteButton.frame.size.width = 44 
     deleteButton.frame.size.height = 44 
     deleteButton.backgroundColor = UIColor.redColor() 
     deleteButton.setImage(UIImage(named: "trash"), forState: .Normal) 

     pinAnnotationView.leftCalloutAccessoryView = deleteButton 

     return pinAnnotationView 
    } 

    return nil 
} 

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) { 
    if let annotation = view.annotation as? PinAnnotation { 
     self.mapView.removeAnnotation(annotation) 
    } 
} 
: 여기

는 pinAnnotation에 인출 액세서리로 버튼을 추가 냈다 코드이며
관련 문제