自定义注释视图图像方向

时间:2016-05-10 16:50:26

标签: ios

我有一个自定义类,我可以在其中添加区分该类型的变量“type”,这是更改图标的选项,但我不知道我可以在哪里制作更改图标,我试图在方法mapView没有得到结果     导入UIKit        导入CoreData         导入MapKit

    class MKAnnotationCostum: NSObject, MKAnnotation{

        var coordinate :  CLLocationCoordinate2D
        var title :  String?
        var subtitle :  String?
        var tipo:String?
        var image: UIImage?

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

我希望根据tipo获得一个不同的图像

import UIKit
import MapKit
import CoreData

class ThreeViewController: UIViewController,MKMapViewDelegate {

    @IBOutlet weak var myMap: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
            //viewDidAppear(true)
            myMap.delegate =  self
        }
    override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)


        let request =  NSFetchRequest(entityName: "PUNTO")
        if let results = try? context.executeFetchRequest(request) {
            for resultado in results {

                let latitud:CLLocationDegrees = Double(resultado.valueForKey("puntoLatitud") as! NSNumber)
                let longitud:CLLocationDegrees = Double(resultado.valueForKey("puntoLongitud") as! NSNumber)

                let lateDelta:CLLocationDegrees = 0.01
                let longDelta:CLLocationDegrees = 0.01

                let span: MKCoordinateSpan = MKCoordinateSpanMake(lateDelta, longDelta)
                let location:  CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitud,longitud)

                let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)


                myMap.setRegion(region, animated: true)

                let pointAnnotation = MKAnnotationCostum(coordinate: location, title: resultado.valueForKey("puntoDireccion") as! String, subtitle: "Latitud: \(resultado.valueForKey("puntoLatitud")!), Longitud: \(resultado.valueForKey("puntoLongitud")!) ", tipo:resultado.valueForKey("clasId") as! String)

//                pointAnnotation.coordinate = location
//                pointAnnotation.title  =  String(resultado.valueForKey("puntoDireccion")!)
//                pointAnnotation.subtitle = String("Latitud: \(resultado.valueForKey("puntoLatitud")!), Longitud: \(resultado.valueForKey("puntoLongitud")!) ")

               print("color: \(pointAnnotation.tipo)")

                   myMap.addAnnotation(pointAnnotation)
                  //mapView(myMap, viewForAnnotation: pointAnnotation)
            }
        }
        myMap.showsUserLocation = true
    }

    func mapView(mapaView: MKMapView, viewForAnnotation anotacion: MKAnnotation) -> MKAnnotationView? {

        if !(anotacion is MKAnnotationCostum) {

            let reusarId = "anotacion"

            var anotacionView = mapaView.dequeueReusableAnnotationViewWithIdentifier(reusarId)
            if anotacionView == nil {
                anotacionView = MKAnnotationView(annotation: anotacion, reuseIdentifier: reusarId)

                anotacionView!.canShowCallout = true
                anotacionView!.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "Amarillo"))
            }
            else {

                anotacionView!.annotation = anotacion
            }

            return anotacionView
        }

        let reusarId = "anotacion"

        var  anotacionView = mapaView.dequeueReusableAnnotationViewWithIdentifier(reusarId)
        let costum = anotacion as! MKAnnotationCostum
        if anotacionView == nil {
            anotacionView = MKAnnotationView(annotation: costum, reuseIdentifier: reusarId)
            //let costumView = anotacionView as! MKAnnotationCostum
            anotacionView!.image = UIImage(named:"Amarillo")
            anotacionView!.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "marca"))
            anotacionView!.canShowCallout = true

        }else {
            anotacionView!.annotation = anotacion
        }
        return anotacionView
    }

1 个答案:

答案 0 :(得分:0)

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void login() {
        //Open Drawer to click on navigation.
        onView(withId(R.id.drawer_layout))
                .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
                .perform(open()); // Open Drawer
    }
}