Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3601376
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:36:51+00:00 2026-05-18T20:36:51+00:00

This is about an iPhone App using MKMapKit: I created a custom MKAnnotationView for

  • 0

This is about an iPhone App using MKMapKit:

I created a custom MKAnnotationView for a draggable Annotation. I want to create a custom animation. I set a custom pin image and the annotation is draggable (which both is not shown here, it happens in the mapview) with the following code:

- (void) movePinUpFinished {

     [super setDragState:MKAnnotationViewDragStateDragging];
     [self setDragState:MKAnnotationViewDragStateDragging];
}

- (void) setDragState:(MKAnnotationViewDragState) myState {
     if (myState == MKAnnotationViewDragStateStarting) {
          NSLog(@"starting");
          CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20);
          self.center = endPoint;
          [self movePinUpFinished];
     }
     if (myState == MKAnnotationViewDragStateEnding) {
          NSLog(@"ending");
          [super setDragState:MKAnnotationViewDragStateEnding];
          [self setDragState:MKAnnotationViewDragStateNone];
          [super setDragState:MKAnnotationViewDragStateNone];
     }
     if (myState == MKAnnotationViewDragStateDragging) {
          NSLog(@"dragging");
     }
     if (myState == MKAnnotationViewDragStateCanceling) {
          NSLog(@"cancel");
     }
     if (myState == MKAnnotationViewDragStateNone) {
          NSLog(@"none");
     }
}

Everything works fine, the annotation is moved up a bit, is draggable and when i release the annotation, the mapview receives the “dragstateending”.

But now I want the animation to run over a time period and change the dragStateStarting to the following:

if (myState == MKAnnotationViewDragStateStarting) {
          NSLog(@"starting");
          CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20);
          [UIView animateWithDuration:1.0
           animations:^{ self.center = endPoint; }
           completion:^(BOOL finished){ [self movePinUpFinished]; }];
     }

The animations runs as wanted over the period of a second and the annotation is draggable. But when I release the annotation, the mapview is not receiving the ending through the delegat. What I also recognized was that when I am doing the animation with “UIView animateWithDuration…” is that immedently after beginning the dragging, as the animation starts, the ballon of the annotation opens. When i am setting the new center without the animation, the balloon keeps closed and is only opened after finishing the dragging by releasing the annotation.

What am I doing wrong? Is this the right way to override setDragState. Do I really have to call the super class? But without setting the dragstate in the superclass my mapview didnt realized the changes of the dragstate.

I wonder about the original implementation of MKPinAnnotationView, but because it is an internal Class I couldn’t find a description of the setDragState method.

Thx for help. Cheers,

Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:36:52+00:00Added an answer on May 18, 2026 at 8:36 pm

    I had the pin drag working but was trying to figure out why the pin annimations that occur when you don’t override setDragState – no longer work in my implementation. Your question contained my answer .. Thanks!

    Part of the problem with your code is that once you override the setDragState function, per the xcode documentation, you are responsible for updating the dragState variable based on the new state coming in. I would also be a little concerned about your code calling itself (setDragState calling [self setDragState]).

    Here is the code I ended up (with your help) that does all of the lifts, drags and drops as I expect them to occur. Hope this helps you too!

    - (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated
    {
        if (newDragState == MKAnnotationViewDragStateStarting)
        {
            // lift the pin and set the state to dragging
    
            CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20);
            [UIView animateWithDuration:0.2
                             animations:^{ self.center = endPoint; }
                             completion:^(BOOL finished)
                                 { self.dragState = MKAnnotationViewDragStateDragging; }];
        }
        else if (newDragState == MKAnnotationViewDragStateEnding)
        {
            // save the new location, drop the pin, and set state to none
    
            /* my app specific code to save the new position
            objectObservations[ACTIVE].latitude = pinAnnotation.coordinate.latitude;
            objectObservations[ACTIVE].longitude = pinAnnotation.coordinate.longitude;
            posChanged = TRUE;
            */
    
            CGPoint endPoint = CGPointMake(self.center.x,self.center.y+20);
            [UIView animateWithDuration:0.2
                             animations:^{ self.center = endPoint; }
                             completion:^(BOOL finished)
                                 { self.dragState = MKAnnotationViewDragStateNone; }];
        }
        else if (newDragState == MKAnnotationViewDragStateCanceling)
        {
            // drop the pin and set the state to none
    
            CGPoint endPoint = CGPointMake(self.center.x,self.center.y+20);
            [UIView animateWithDuration:0.2
                             animations:^{ self.center = endPoint; }
                             completion:^(BOOL finished)
                                 { self.dragState = MKAnnotationViewDragStateNone; }];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display current time in my iPhone app using my own custom
Is there any possible to develop the Iphone App using Eclipse IDE in Windows?
I'm constructing a small iphone app and using a singleton to store and update
On my iPhone app I'm using a UISearchBar (without a Search Display Controller). I
I am building an iPhone audio app using Audio Sessions. Prototype was functioning till
I just tried compileing my iPhone app against OS 3.0 and I get a
I'm writing an iPhone app which downloads a tar-gzipped file from a Webserver, then
I'm making my first iPhone app. I could solve most of my problems browsing
I checked out the three20 source and was trying to follow this guide to
I'm considering using Go as a low-level, performant language alternative to C/Objective-C to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.