我是iOS开发人员。我正在尝试显示自定义标注视图点击(图钉)。此标注视图包含两个按钮。我已经尝试使用下面给出的代码显示自定义标注视图。
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
var calloutSize:CGSize = CGSizeMake(200.0, 110.0)
confirm = MKAnnotationView(frame: CGRect(x: -calloutSize.width/2, y: -calloutSize.height - 10, width: calloutSize.width, height:calloutSize.height))
confirm!.backgroundColor = UIColor(white: 0.9, alpha: 1)
confirm!.alpha = 0.7
let button_Yes = UIButton(frame: CGRectMake(0, 0, 200, 54))
button_Yes.backgroundColor = UIColor.purpleColor()
button_Yes.setTitle("See listing detail", forState: UIControlState.Normal)
button_Yes.addTarget(self, action:Selector( "checkout:"), forControlEvents: UIControlEvents.TouchUpInside)
button_Yes.userInteractionEnabled = true
button_Yes.tag = 1
confirm!.addSubview(button_Yes)
let button_No = UIButton(frame: CGRectMake(0,calloutSize.height / 2, 200, 54))
button_No.backgroundColor = UIColor.purpleColor()
button_No.setTitle("Get directions", forState: UIControlState.Normal)
button_No.addTarget(self, action:Selector("checkin:"), forControlEvents: UIControlEvents.TouchUpInside)
button_No.userInteractionEnabled = true
button_No.tag = 2
confirm!.addSubview(button_No)
view.addSubview(confirm!)
}
func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) {
confirm!.removeFromSuperview()
}
答案 0 :(得分:-1)
为此你需要创建MKAnnotationView
和XIB的子类,
使用此功能,您可以在
mapView(_:viewForAnnotation:)
以下是最好的例子: https://www.cocoacontrols.com/controls/gikanimatedcallout https://www.cocoacontrols.com/controls/multirowcalloutannotationview