2016-04-13 12 views
1

MKAnnotationのイメージを回転しようとしていますが、成功するとタイトルも回転しています。タイトルをまっすぐに保つ方法はありますか?どんな助けでも本当にありがとう!ここmkannotationイメージをタイトル以外に回転する

が私のコードである:のviewDidLoadで

()...

let middlePoint = CustomPointAnnotation() 
middlePoint.coordinate = self.coordinates 
middlePoint.imageName = "routemiddle" 
middlePoint.title = "\(hourDetailedRoute):\(minuteDetailedRoute)" 
middlePoint.courseDegrees = self.vehicleChangeCourse 
self.mapa.addAnnotation(middlePoint) 


func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
    if !(annotation is CustomPointAnnotation) { 
     return nil 
    } 

    let reuseId = "annotation" 

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) 
    if anView == nil { 
     anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
     anView!.canShowCallout = true 
    } 
    else { 
     anView!.annotation = annotation 
    } 

    let cpa = annotation as! CustomPointAnnotation 
    anView!.image = UIImage(named:cpa.imageName) 
    anView!.transform = CGAffineTransformRotate(self.mapa.transform, CGFloat(degreesToRadians(cpa.courseDegrees))) 


    return anView 
} 

クラスCustomPointAnnotation:MKPointAnnotation {

var imageName: String! 
var courseDegrees = 0.0 

}

enter image description here

答えて

0

私はそれを理解しました!画像全体を回転させるのではなく、画像だけを回転させるだけでした。

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
    if !(annotation is CustomPointAnnotation) { 
     return nil 
    } 

    let reuseId = "annotation" 

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) 
    if anView == nil { 
     anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
     anView!.canShowCallout = true 
    } 
    else { 
     anView!.annotation = annotation 
    } 

    let cpa = annotation as! CustomPointAnnotation 
    var imagePin = UIImage(named:cpa.imageName) 
    imagePin = imagePin?.rotateImage(cpa.courseDegrees) 
    anView!.image = imagePin 

    return anView 
} 
関連する問題