Я пытаюсь повернуть свою пользовательскую аннотацию при изменении координат. Я могу успешно изменить координату, но попробовал все, чтобы вращать ее без везения. Основная идея состоит в том, чтобы иметь плоскость и задавать ее направление вращением.Swift MKAnnotationView Rotate
Вот мой код:
import UIKit
import MapKit
class CustomPointAnnotation: MKPointAnnotation {
var imageName: String!
}
class ViewController: UIViewController, MKMapViewDelegate {
var myAnnot : MKPointAnnotation!
var myDegree = 0.0
var mylat = 41.1036
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.mapType = MKMapType.Hybrid
mapView.showsUserLocation = true
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
println("HOMESET")
var homeGPSData = CLLocation(latitude: 41.1036, longitude: 29.3822)
println(homeGPSData)
self.myAnnot = MKPointAnnotation()
myAnnot.coordinate = CLLocationCoordinate2DMake(homeGPSData.coordinate.latitude, homeGPSData.coordinate.longitude)
myAnnot.title = "Base"
var rangeCircle : MKCircle = MKCircle(centerCoordinate: homeGPSData.coordinate, radius: 20000)
mapView.addOverlay(rangeCircle)
mapView.addAnnotation(myAnnot)
var myLoop = NSTimer.scheduledTimerWithTimeInterval(0.0004, target: self, selector: "rotateAndMoveAnnotation", userInfo: nil, repeats: true)
}
func rotateAndMoveAnnotation() {
var lon = 29.3822
var homeGPSData = CLLocation(latitude: self.mylat, longitude: lon)
myAnnot.coordinate = CLLocationCoordinate2DMake(homeGPSData.coordinate.latitude, homeGPSData.coordinate.longitude)
self.mylat = self.mylat + 0.001
self.myDegree = self.myDegree + 1
}
func degreesToRadians(degrees: Double) -> Double { return degrees * M_PI/180.0 }
func radiansToDegrees(radians: Double) -> Double { return radians * 180.0/M_PI }
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
}
anView.image = UIImage(named: "sprite.png")
return anView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}