gpt4 book ai didi

ios - 旋转 MKAnnotation 图像而不是标题

转载 作者:行者123 更新时间:2023-11-28 08:40:37 26 4
gpt4 key购买 nike

我正在尝试为 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
}
class CustomPointAnnotation: MKPointAnnotation {
var imageName: String!
var courseDegrees = 0.0
}

enter image description here

最佳答案

我想通了!我只需要旋转图像而不是旋转整个 View 。

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
}

关于ios - 旋转 MKAnnotation 图像而不是标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36601910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com