現在、注釈のピンを変更する方法に関するいくつかのチュートリアルを見てきました。しかし、私が遭遇したのは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!
}
情報を得るために見た過去のスレッド