我是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
那麼究竟是什麼問題或問題呢?順便說一下,我建議使用普通的UIView,而不是爲標註視圖創建MKAnnotationView。 – Anna
確切的問題是,當我選擇引腳時,自定義註釋顯示兩行按鈕。而且我也使用UIView,但這不起作用。請爲您的理解找一個圖片網址。 –
您需要詳細解釋「不工作」的含義。編譯器錯誤,運行時錯誤,其他 - 確切地說 - 究竟發生了什麼?你做了什麼調試?建議不要使用MKAnnotationView作爲_callout_視圖。 – Anna