我目前已经浏览了一些关于如何更改注释引脚的教程。但我遇到的只是 xcode 7 中的错误(主要是所有断点,它无法正常工作)。我想要做的是使用我的资产文件夹中的云,并用它替换正常的注释。从我看到的指南中,人们只是在使用我不确定它们应该放在哪里的 png 文件?但尽管如此,对代码有什么建议可以让我替换它吗?
干杯和感谢
这是我的代码
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
longPressRecognizer.minimumPressDuration = 1.0
longPressRecognizer.delaysTouchesBegan = true
longPressRecognizer.delegate = self
self.mapView.addGestureRecognizer(longPressRecognizer)
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func handleLongPress(getstureRecognizer : UIGestureRecognizer) {
if getstureRecognizer.state != .Began { return }
let touchPoint = getstureRecognizer.locationInView(self.mapView)
let touchMapCoordinate = mapView.convertPoint(touchPoint, toCoordinateFromView: mapView)
let annotation = MKPointAnnotation()
annotation.coordinate = touchMapCoordinate
mapView.addAnnotation(annotation)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 10, longitudeDelta: 10))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is MKPointAnnotation) {
return nil
}
let reuseId = "Cloud"
var CloudAnnotation = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if CloudAnnotation == nil {
CloudAnnotation = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
CloudAnnotation!.image = UIImage(named:"cloud.png")
CloudAnnotation!.canShowCallout = true
}
else {
CloudAnnotation!.annotation = annotation
}
return CloudAnnotation
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Errors: " + error.localizedDescription)
}
对于 MKAnnotationViewClass
import UIKit
import MapKit
class CustomPointAnnotation: MKPointAnnotation {
var pinCustomImageName:String!
}
我查看的以前的线程以获取信息