2015-05-05 31 views
0

我是iOS開發人員。我試圖顯示自定義標註視圖單擊(pin)。此標註視圖包含兩個按鈕。我試圖用下面給出的代碼顯示自定義標註視圖。如何顯示自定義標註視圖點擊此標誌就像給出的圖像

 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() 
} 

I have embedded a image url, i want to like this callout

+0

那麼究竟是什麼問題或問題呢?順便說一下,我建議使用普通的UIView,而不是爲標註視圖創建MKAnnotationView。 – Anna

+0

確切的問題是,當我選擇引腳時,自定義註釋顯示兩行按鈕。而且我也使用UIView,但這不起作用。請爲您的理解找一個圖片網址。 –

+0

您需要詳細解釋「不工作」的含義。編譯器錯誤,運行時錯誤,其他 - 確切地說 - 究竟發生了什麼?你做了什麼調試?建議不要使用MKAnnotationView作爲_callout_視圖。 – Anna

回答

-1

爲此,您需要創建MKAnnotationView和XIB, 子類使用此,你可以返回標註您的自定義視圖

mapView(_:viewForAnnotation:) 

下面是最好的例子: https://www.cocoacontrols.com/controls/gikanimatedcallout https://www.cocoacontrols.com/controls/multirowcalloutannotationview

+0

我不能使用第三方庫。 –

+0

創建MKAnnotationView和XIB的子類,或者至少可以使用他們已經使用的模式(第三方)。 –

+0

我正在使用swift語言和最新的故事板。 –