How to make IOS map and annotation fall from the air

Source: Internet
Author: User

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
  1. -(Void) mapview :( mkmapview *) mapview didaddannotationviews :( nsarray *) views {
  2. Mkannotationview * AV;
  3. For (av in views ){
  4. Cgrect EndFrame = Av. frame;
  5. Av. frame = cgrectmake (Av. frame. origin. x, Av. frame. origin. y-230.0, Av. frame. size. width, Av. frame. size. height );
  6. [Uiview beginanimations: Nil context: NULL];
  7. [Uiview setanimationduration: 0.45];
  8. [Uiview setanimationcurve: uiviewanimationcurveeaseinout];
  9. [AV setframe: EndFrame];
  10. [Uiview commitanimations];
  11. }
  12. }

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

  1. -(Mkannotationview *) mapview :( mkmapview *) mV viewforannotation :( id <mkannotation>) Annotation
  2. {
  3. If (annotation = mV. userlocation ){
  4. Return nil;
  5. }
  6. Mkpinannotationview * pinview = nil;
  7. Static nsstring * defaultpinid = @ "Custom pin ";
  8. Pinview = (mkpinannotationview *) [MV dequeuereusableannotationviewwithidentifier: defaultpinid];
  9. If (pinview = nil)
  10. {
  11. Pinview = [[[mkpinannotationview alloc] initwithannotation: annotation reuseidentifier: defaultpinid] autorelease];
  12. [Pinview setdraggable: Yes];
  13. }
  14. Pinview. pincolor = mkpinannotationcolorred;
  15. Pinview. canshowcallout = yes;
  16. Pinview. animatesdrop = yes;
  17. Return pinview;
  18. }

Note:

View plain
  1. Pinview. animatesdrop = yes;

.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.