0
我試圖找到一種方法來添加一個鏈接到Swift MapFramework中的Annotation,這個鏈接應該將用戶轉發給WebView,據我所見我找不到任何方法添加一個「可觸摸」鏈接到一個註解字幕在註釋中的Swift鏈接 - > Webview
這是我的代碼,但
class CustomPointAnnotation: MKPointAnnotation {
var imageName: String!
}
var info1 = CustomPointAnnotation()
info1.coordinate = CLLocationCoordinate2DMake(42, -84)
info1.title = "Info1"
info1.subtitle = "Subtitle"
info1.imageName = "1.png"
var info2 = CustomPointAnnotation()
info2.coordinate = CLLocationCoordinate2DMake(32, -95)
info2.title = "Info2"
info2.subtitle = "Subtitle"
info2.imageName = "2.png"
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if !(annotation is CustomPointAnnotation) {
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView.canShowCallout = true
}
else {
anView.annotation = annotation
}
//Set annotation-specific properties **AFTER**
//the view is dequeued or created...
let cpa = annotation as CustomPointAnnotation
anView.image = UIImage(named:cpa.imageName)
return anView
}
是否有可能使用UIGestureRecognizer這個辦法?
我已經嘗試過像
var longpress = UILongPressGestureRecognizer(target: self, action: "newInformation:")
longpress.minimumPressDuration = 2.0
info1.addGestureRecognizer(longpress)
但隨着「ViewController.CustomPointAnnotation沒有一個名爲addGestureRecognizer成員」
許多問題你問的問題已經在[documentation](https://developer.apple.com/library/ios/navigation/)或SO上得到了解答。在文檔中,搜索MKMapView類的引用或閱讀[位置和地圖編程指南](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html)。 SO上的答案目前主要在Objective-C中,但在Swift中完全相同(只需要翻譯語言)。 – Anna 2014-09-03 11:37:49
對於這個當前的問題,典型的方法是通過設置視圖的leftCalloutAccessoryView或rightCalloutAccessoryView來添加標註附件按鈕。以http://stackoverflow.com/questions/25202613/mapkit-in-swift-part-2爲例。點擊按鈕時,地圖視圖將調用calloutAccessoryControlTapped委託方法。在那裏,您可以呈現網絡視圖。 – Anna 2014-09-03 11:39:47
謝謝安娜的幫助,我對這個問題感到抱歉,我只是開始學習迅速和客觀的c,有時即使我看到答案我沒有得到它;)! – 2014-09-03 12:00:42