Swift에서 마크 포인트의 이미지를 변경하는 방법을 이해하지 못합니다. 나는좌표에 대한 특수 효과의 이미지는 어떻게 변경합니까?
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
의 몇 가지 변화를 시도했지만 호출되지는 결코 보인다 나는 그것을 호출 할 강제하는 방법을 모르겠어요.
나는 프로그래밍 방식으로 MKMapView
을 추가 했으므로 iPhone을 사용하는 데 따라 크기 (가로 및 세로)를 전환 할 수 있습니다. (난 아직도 믿을 수 없어이 엑스 코드에 직관적하지 않고 프로그래머는 주위 프로그래밍 할 수 있습니다.)
내 코드입니다 :
@IBAction func addStroke(sender: UIButton) {
NSLog("Add Stroke Touched")
NSLog("X %f Y %f", manager.location.coordinate.latitude, manager.location.coordinate.longitude)
GPSspot = manager.location.coordinate
annotation.setCoordinate(GPSspot)
annotation.title = "Stroke"
let useID = "test"
var myAnnotation = mapHole.dequeueReusableAnnotationViewWithIdentifier(useID)
if (myAnnotation == nil) {
myAnnotation = MKAnnotationView(annotation: annotation, reuseIdentifier: useID)
myAnnotation.image = UIImage(named: "ballSmall.png")
myAnnotation.canShowCallout = true
myAnnotation.enabled = true
} else {
myAnnotation.annotation = annotation
}
mapHole.viewForAnnotation(annotation)
mapHole.addAnnotation(annotation)
}
//MARK: - Map Kit
var mapRect = MMRect(xLoc: 502, yLoc:20, yWidth:218, xHeight:386)
var mapHole:MKMapView! //= MKMapView() as MKMapView
var annotation = MKPointAnnotation()
var MAView:MKAnnotationView!
//MARK: - GPS Locations
var manager:CLLocationManager!
var GPSspot:CLLocationCoordinate2D!
var span:MKCoordinateSpan!
var region:MKCoordinateRegion!
//MARK: - Default Initializer
override func viewDidLoad() {
super.viewDidLoad()
//MARK: Locations
manager = CLLocationManager()
if (CLLocationManager.locationServicesEnabled()) {
NSLog("locations services started")
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
} else {
NSLog("location services failed")
}
//MARK: MKMapView
mapHole = MKMapView(frame: mapRect.textRect)
span = MKCoordinateSpanMake(0.001, 0.001)
GPSspot = manager.location.coordinate
region = MKCoordinateRegion(center: GPSspot, span: span)
mapHole.setRegion(region, animated: true)
mapHole.mapType = MKMapType.Satellite
mapHole.showsUserLocation = true
self.view.addSubview(mapHole)
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKUserLocation {
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView (annotation: annotation, reuseIdentifier: reuseId)
anView.image = UIImage(named:"ballSmall.png")
anView.canShowCallout = true
} else {
anView.annotation = annotation
}
return anView
}
누군가가 도와 드릴까요? 고맙습니다! 나는이 일을하고 일주일 정도 책을 읽었으므로 나는 그것을 얻지 못했다.
감사합니다 !!!!! 나는 델리게이트를 추가하는 것을 놓쳤다. 고맙습니다! (다음 주 해결할 긴 문제를 해결할 예정입니다.) – Scuttle