Category: iPhone tutorial views and comments (0)
Anyone who has played the Google app knows that when we add a destination to a map, annotationview falls from top to bottom. How can this effect be achieved? In practice, I have found two ways to achieve this effect.
The first method is to implement mkmapviewdelegate, and then implement the animation effect of the fall by yourself. The Code is as follows:
View plain
- -(Void) mapview :( mkmapview *) mapview didaddannotationviews :( nsarray *) views {
- Mkannotationview * AV;
- For (av in views ){
- Cgrect EndFrame = Av. frame;
- Av. frame = cgrectmake (Av. frame. origin. x, Av. frame. origin. y-230.0, Av. frame. size. width, Av. frame. size. height );
- [Uiview beginanimations: Nil context: NULL];
- [Uiview setanimationduration: 0.45];
- [Uiview setanimationcurve: uiviewanimationcurveeaseinout];
- [AV setframe: EndFrame];
- [Uiview commitanimations];
- }
- }
The second method is very simple. You only need to set the attribute value of an annotationview, which is also implemented in the mkmapviewdelegate method. The Code is as follows: view plain
- -(Mkannotationview *) mapview :( mkmapview *) mV viewforannotation :( id <mkannotation>) Annotation
- {
- If (annotation = mV. userlocation ){
- Return nil;
- }
- Mkpinannotationview * pinview = nil;
- Static nsstring * defaultpinid = @ "Custom pin ";
- Pinview = (mkpinannotationview *) [MV dequeuereusableannotationviewwithidentifier: defaultpinid];
- If (pinview = nil)
- {
- Pinview = [[[mkpinannotationview alloc] initwithannotation: annotation reuseidentifier: defaultpinid] autorelease];
- [Pinview setdraggable: Yes];
- }
- Pinview. pincolor = mkpinannotationcolorred;
- Pinview. canshowcallout = yes;
- Pinview. animatesdrop = yes;
- Return pinview;
- }
Note:
View plain
- Pinview. animatesdrop = yes;
.