简体   繁体   English

迅速-MapKit中的自定义注释偏移

[英]swift - Custom Annotation Offset in MapKit

I have the following annotation with a callout in the form of a xib file that looks like this: 我具有以下xib文件形式的标注和标注,如下所示:

Current state 当前状态

I would like to know how to offset the annotation callout so that the origin of the annotation callout is not at the point of the annotation itself, but offset by 10 points on the y axis, so it would be a little bit above the annotation. 我想知道如何偏移注释标注,以便注释标注的原点不在注释本身的点上,而是在y轴上偏移10点,因此它将比注释高一点。 Is there a way to do this? 有没有办法做到这一点?

Can you help me achieve this? 你能帮我实现这个目标吗? Any help is appreciated, thanks! 任何帮助表示赞赏,谢谢!

Still looking for the solution. 仍在寻找解决方案。

I set it in swift code like this: 我将其设置为如下所示的快速代码:

class CarAnnotationView: MKAnnotationView {
    override var annotation: MKAnnotation? {
        willSet {
            guard let carAnnotation = newValue as? CarAnnotation else { return }
            self.calloutOffset = CGPoint(x: -5, y: 5)
            ....
        }
    }
}

The important line is: 重要的一行是:

self.calloutOffset = CGPoint(x: -5, y: 5)

I found the solution for my case, it was just a question of setting the origin of the custom annotationView that I creted from a xib file. 我找到了适合我的情况的解决方案,这只是设置我从xib文件创建的自定义注解视图的来源的问题。

Like so: 像这样:

newCustomCalloutView.frame.origin.y -= newCustomCalloutView.frame.height + 3

The important part is the + 3 in the line above. 重要的是上面一行中的+ 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM