Many projects need to implement custom pins and custom CalloutAnnotationView, this article may be helpful for many of the children’s shoes! First look at what I do renderings
inside the pins and CalloutAnnotationView are not the same as the system, should be able to cope with most of the scenes, nonsense, not to mention the subject.
The first to know the relationship between the development of MKAnnotation and MKAnnotationView of the two, if this did not understand that it is difficult to understand. I talk about their own understanding – that is, the relationship between model and view, we can try to ponder should not understand. Effect of map in the above either irregular orange red or pop-up graphics are known to have pin pin, click event in Apple’s system map. Second to the MKMapView as they often do, understand and use UITableView. Third is to do it yourself.
Look at the first layer pins and the red and blue text pins. These map data should be server access, is the establishment of a model receiving the data here defines a Location model for the received data
now the data has to be linked to the pins Not to mention here, we first look at the meaning of the two functions,
I told you to use UITableView and custom pin to understand, it is not difficult to understand the above first function is corresponding to the
– (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath/ *) indexPath
second function I would not say the click event. Since you can now understand the point that get to the point, if we can put a pin when the custom cell to use, it must be repeated use, this can see the official API document written very clearly that we show the custom pin of the first layer. The above
model we have, and now have MKAnnotation associated, since it is so sure to create a custom class that inherits from MKAnnotation (native MKAnnotation only three attributes to call you certainly can not meet the actual needs of the project)
.M file which is a direct set method and the ZLocationAnnotation assignment, the code is too lazy to attach. Through the above two methods
screenshot we should also see the end users see is definitely MKAnnotationView, also said in front of the relationship between MKAnnotation and MKAnnotationView is model and view, now model has, the association requires and MKAnnotationView. I’m here is a simple custom View via Xib drag line. Why don’t I just customize the MKAnnotationView view? Very simple, can not directly out of a MKAnnotationView
[[[NSBundle mainBundle] loadNibNamed:@, “Xib” owner:nil options:nil] lastObject] View to load the Xib method provided here;
now has also set up the interface just said Xcode can’t directly out of a MKAnnotationView, it would be just a custom view and MKAnnotationView, then we have to create a succession of MKAnnotationView view, I am here is so defined
to show just Xib custom View in the initialization method which can be added inside. It should be noted that many boots encounter this problem click Custom pin no effect, or override the hit method, I adopt second kinds of methods:
You can see my
MKAnnotationView bounds set to the View pin and custom size, why many boots encountered invalid click pin? Because it can be a small range of clicks, followed by the two method is a simple initialization assignment. In conjunction with just showing the MKAnnotationView proxy method of course you have to call the loading method addAnnotation.
here, your custom pin display is no problem, as for the custom CalloutAnnotationView my next episode.