接着上篇文章继续讲解自定义CalloutAnnotationView.
上面讲过,实际上它本身也是一个Annotation,那就之前一样定义了,只不过一般项目里面CalloutAnnotationView稍微复杂点,大多都需要自定义,下面我们看看具体的实现。
上篇有效果图我这里在贴上做的另外的效果图其实都是差不多。

首先,既然你的CalloutAnnotationView是点击大头针时候那两者之间肯定有关联。你得把坐标告诉这个CalloutAnnotationView,上面我们已经知道了 大头针的CLLocationCoordinate2D,现在只要赋值给它就行。前面说了自定义CalloutAnnotationView其实和自定义大头针是一样,那我这里就不重复了,直接上代码,



这里面要注意的一点是 如果你的CalloutAnnotationView有点击事件 那你需要额外的注意他的可点击区域 ,否则的话可能出现点击无效,

我在代码里面已经写了,这里的偏移量需要你们自己来调。
现在就是你的UI部分了 我这里还是和之前大头针一样直接用xib

实现部分和上一篇一样,最好大家自己动手写写。
最后就是如何调用展示的问题,上次也说过其实他的原理和tableview类似,都有点击方法

这里面代码里面加了判断是否是需要点的大头针,具体的你可以根据你的项目来做相应的调整。
其实最后实现下来还是和大头针是一样的,只要你前面实现没问题,我觉得CalloutAnnotationView也是一样。
网友评论