Note that there are some explanatory texts on larger screens.

plurals
  1. POSubclassing MKAnnotationView and overriding setDragState
    primarykey
    data
    text
    <p>This is about an iPhone App using MKMapKit:</p> <p>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:</p> <pre><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"); } } </code></pre> <p>Everything works fine, the annotation is moved up a bit, is draggable and when i release the annotation, the mapview receives the "dragstateending".</p> <p>But now I want the animation to run over a time period and change the dragStateStarting to the following:</p> <pre><code>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]; }]; } </code></pre> <p>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.</p> <p>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.</p> <p>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.</p> <p>Thx for help. Cheers,</p> <p>Ben</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload