Swift中的MapKit,第2部分

Swift中的MapKit,第2部分,第1张

概述我正在尝试使用 Swift中的Map Kit.我尝试在地图上显示区域,一个引脚(MKPinAnnotationView)和当前位置.一切都很好.我尝试添加Disclosure Button并拦截它. Disclosure Button已添加,但无法拦截攻丝. 函数pinPressed方法calloutAccessoryControlTapped不起作用…. 这是一个示例代码: import UIK 我正在尝试使用 Swift中的Map Kit.我尝试在地图上显示区域,一个引脚(MKPinAnnotationVIEw)和当前位置.一切都很好.我尝试添加disclosure button并拦截它. disclosure button已添加,但无法拦截攻丝.

函数pinpressed方法calloutAccessoryControlTapped不起作用….

这是一个示例代码:

import UIKitimport MapKitimport CoreLocationclass VIEwController: UIVIEwController,MKMapVIEwDelegate,CLLocationManagerDelegate {@IBOutlet weak var mainMapVIEw: MKMapVIEw!var locationManager = CLLocationManager()overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    locationManager.delegate = self    locationManager.desiredAccuracy = kCLLocationAccuracyBest    locationManager.requestAlwaysAuthorization()    locationManager.startUpdatingLocation()    var objectLatitude = 53.204526    var objectLongitude = 50.111751    var currentLatitude = 53.203715    var currentLongitude =  50.160374    var latDelta = 0.05    var longDelta = 0.05    var currentLocationSpan: MKCoordinateSpan = MKCoordinateSpanMake(latDelta,longDelta)    var currentLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude)    var currentRegion: MKCoordinateRegion = MKCoordinateRegionMake(currentLocation,currentLocationSpan)    self.mainMapVIEw.setRegion(currentRegion,animated: true)    var objectLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(objectLatitude,objectLongitude)    var objectAnnotation = MKPointAnnotation()    objectAnnotation.coordinate = objectLocation    objectAnnotation.Title = "St. George's Church"    objectAnnotation.subTitle = "Church of the Great Martyr St. George"    self.mainMapVIEw.addAnnotation(objectAnnotation)}func mapVIEw(mapVIEw: MKMapVIEw!,vIEwForAnnotation annotation: MKAnnotation!) -> MKAnnotationVIEw! {        if annotation is MKUserLocation {            //return nil so map vIEw draws "blue dot" for standard user location            return nil        }        let reuseID = "pin"        var pinVIEw = mapVIEw.dequeueReusableAnnotationVIEwWithIDentifIEr(reuseID) as? MKPinAnnotationVIEw        if pinVIEw == nil {            pinVIEw = MKPinAnnotationVIEw(annotation: annotation,reuseIDentifIEr: reuseID)            pinVIEw!.canShowCallout = true            pinVIEw!.animatesDrop = true            pinVIEw!.pincolor = .Purple            pinVIEw!.rightCalloutAccessoryVIEw = UIbutton.buttonWithType(.Detaildisclosure) as UIbutton        }        else {            pinVIEw!.annotation = annotation        }        return pinVIEw}func pinpressed(mapVIEw: MKMapVIEw!,annotationVIEw: MKAnnotationVIEw,calloutAccessoryControlTapped control: UIControl) {    if control == annotationVIEw.rightCalloutAccessoryVIEw {        println("disclosure pressed!")    }}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()}}
解决方法 calloutAccessoryControlTapped委托方法必须命名为mapVIEw(annotationVIEw:calloutAccessoryControlTapped :).

您不能使用自己的名称,如pinpressed(…).

这适用于任何委托方法,并由协议规定.

所以它应该是:

func mapVIEw(mapVIEw: MKMapVIEw!,calloutAccessoryControlTapped control: UIControl) {    if control == annotationVIEw.rightCalloutAccessoryVIEw {        println("disclosure pressed!")    }}
总结

以上是内存溢出为你收集整理的Swift中的MapKit,第2部分全部内容,希望文章能够帮你解决Swift中的MapKit,第2部分所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1004485.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存