2015-09-21 6 views
5

Ich benutze ein Tutorial zum Erstellen meiner ersten App. http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorialAnpassen von PinTintColor an Ray Wenderlich Tutorial für Mapkit

Ive suchte nach pintintcolor, aber nichts kommt auf.

Grundsätzlich verwendet das Tutorial diesen Code um die Farbe einzustellen

// pinColor for disciplines: Sculpture, Plaque, Mural, Monument, other 
func pinColor() -> MKPinAnnotationColor{ 
    switch discipline { 
    case "Sculpture", "Plaque": 
     return .Red 
    case "Mural", "Monument": 
     return .Purple 
    default: 
     return .Green 

Das Problem ist, das ist, was Apple auf der Entwickler-Website

https://developer.apple.com/library/mac/releasenotes/General/APIDiffsMacOSX10_11/Swift/MapKit.html

Modified MKPinAnnotationView Erklärung

hat Von:

class MKPinAnnotationView : MKAnnotationView { 
    var pinColor: MKPinAnnotationColor 
    var animatesDrop: Bool 
} 

An:

class MKPinAnnotationView : MKAnnotationView { 
    class func redPinColor() -> NSColor 
    class func greenPinColor() -> NSColor 
    class func purplePinColor() -> NSColor 
    var pinTintColor: NSColor! 
    var animatesDrop: Bool 
    var pinColor: MKPinAnnotationColor 
} 

Das Tutorial Ray Wenderlich ist die Installation ein gutes Stück anders, so verstehe ich nicht ganz, wie es die gleiche Art und Weise wie es einzurichten. Ich habe ein paar verschiedene Konfigurationen ausprobiert, aber ich kann es nicht zum Laufen bringen.

Jede Hilfe willkommen

Prost

Antwort

2

Statt Verwendung Eigenschaft pinColor (veraltet), verwenden Eigenschaft pinTintColor (iOS9)

//view.pinColor = MKPinAnnotationColor.Green 

view.pinTintColor = UIColor.greenColor() 

//UIColor functions 
public class func blackColor() -> UIColor // 0.0 white 
public class func darkGrayColor() -> UIColor // 0.333 white 
public class func lightGrayColor() -> UIColor // 0.667 white 
public class func whiteColor() -> UIColor // 1.0 white 
public class func grayColor() -> UIColor // 0.5 white 
public class func redColor() -> UIColor // 1.0, 0.0, 0.0 RGB 
public class func greenColor() -> UIColor // 0.0, 1.0, 0.0 RGB 
public class func blueColor() -> UIColor // 0.0, 0.0, 1.0 RGB 
public class func cyanColor() -> UIColor // 0.0, 1.0, 1.0 RGB 
public class func yellowColor() -> UIColor // 1.0, 1.0, 0.0 RGB 
public class func magentaColor() -> UIColor // 1.0, 0.0, 1.0 RGB 
public class func orangeColor() -> UIColor // 1.0, 0.5, 0.0 RGB 
public class func purpleColor() -> UIColor // 0.5, 0.0, 0.5 RGB 
public class func brownColor() -> UIColor // 0.6, 0.4, 0.2 RGB 
public class func clearColor() -> UIColor // 0.0 white, 0.0 alpha 

Hier das vollständige Bild:

import MapKit 

class MyAnnotation: MKAnnotation, NSObject 
{ 
    let identifier: String 
    let title: String? 
    let subtitle: String? 
    let coordinate: CLLocationCoordinate2D 

    init(identifier: String, title: String, subtitle: String, coordinate: CLLocationCoordinate2D) 
    { 
     self.identifier = identifier 
     self.title = title 
     self.subtitle = subtitle 
     self.coordinate = coordinate 

     super.init() 
    } 

    func mapItem() -> MKMapItem 
    { 
     let addressDictionary = [String(CNPostalAddressStreetKey): self.subtitle!] 
     let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDictionary) 

     let mapItem = MKMapItem(placemark: placemark) 
     mapItem.name = self.title 

     return mapItem 
    } 
} 


func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? 
{ 
    if let annotation = annotation as? MyAnnotation 
    { 
     let identifier = annotation.identifier 
     var view = MKPinAnnotationView() 

     if let dequeuedView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as! MKPinAnnotationView! 
     { 
      view = dequeuedView 
      view.annotation = annotation 
     } 
     else 
     { 
      view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
      view.animatesDrop = true 
      view.canShowCallout = true 

      switch identifier 
      { 
       case "Sculpture", "Plaque": 
        view.pinTintColor = UIColor.redColor() 
       case "Mural", "Monument": 
        view.pinTintColor = UIColor.purpleColor() 
       default: 
        view.pinTintColor = UIColor.greenColor() 
      } 
     } 
     return view 
    } 
    return nil 
} 
+0

Also habe ich versucht, dies statt, was ich // pinColor für Disziplinen ursprünglich geschrieben: Skulptur, Plaque, Wandmalerei, Monument, andere func pinTintColor() -> UIColor { Schalter Disziplin { Fall "Skulptur", "Plaque": return .grayColor() Fall "Mural", "Monument": re Turn .purpleColor() default: return .orangeColor() Es wird keine Fehler, aber es ändert sich nicht die Farbe der Pins? – travis

+0

Habe es funktioniert, habe vergessen, pincolor in pinTintColor in VCMapView zu ändern. Danke für Ihre Hilfe! – travis

+0

Ok, viel Glück. Vergiss nicht, über den Pfeil in meinem Post abzustimmen =) –

6

Falls jemand anderes dem Tutorial folgt und den folgenden Fehler sieht: "'M "KPinAnnotationColor" wurde in iOS 9.0 nicht mehr unterstützt: Verwenden Sie stattdessen pinTintColor von MKPinAnnotationView. "

Aktualisieren Sie einfach die pinColor-Routine, um stattdessen einen UIColor-Wert zurückzugeben.

func pinColor() -> UIColor { 
    switch discipline { 
    case "Sculpture", "Plaque": 
     return UIColor.redColor() 
    case "Mural", "Monument": 
     return UIColor.purpleColor() 
    default: 
     return UIColor.greenColor() 
    } 
} 

Und dann der entsprechende Anruf die pinTintColor wie so einzustellen:

view.pinTintColor = annotation.pinColor()