如何旋转箭头(图像),使其不旋转CalloutView

时间:2019-08-01 11:09:01

标签: swift mapkit mkannotationview mkpointannotation calloutview

我需要转动地图上的箭头(customAnnotationView),以使calloutView不会旋转(示例1)。

当我仅旋转图像时: 箭头未设置在中心且大小不同(示例2)。

示例1 enter image description here

示例2 enter image description here

Example 1
annotationView?.transform = CGAffineTransform(rotationAngle: CGFloat((-180.0 * .pi / 180) - -customPointAnnotation.ang))

Example 2
annotationView?.image = UIImage(named: customPointAnnotation.pinCustomImageName)?.rotate(radians: CGFloat((90.0 * .pi / 180) - -customPointAnnotation.ang))

1 个答案:

答案 0 :(得分:0)

我希望它能解决您的问题

 let pinImage = UIImage(named: "customPointAnnotation.pinCustomImageName")
        let size = CGSize(width: 50, height: 50) // size of your choice
        UIGraphicsBeginImageContext(size)
        pinImage!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
        let rotatedImage =  . resizedImage rotate(radians: CGFloat((90.0 * .pi / 180) - -customPointAnnotation.ang)) //if still not set do check by changing image or by slightly changing redians angle values.
        annotationView?.image = rotatedImage