When tapping on my annotation I want to show a callout. That works, so far so good. If I want to drag my annotation to a different position I have to tap it first, the callout shows, and I can start dragging.
Is there a way to only show the callout on shortPress and start dragging immediately if I do a longPress?
My code for dragging:
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, didChangeDragState newState: MKAnnotationViewDragState, fromOldState oldState: MKAnnotationViewDragState) {
var liftValue:CGFloat = 40.0
if (newState == MKAnnotationViewDragState.Starting)
{
var endPoint = CGPointMake(view.center.x, view.center.y - liftValue)
UIView.animateWithDuration(0.2, animations: { () -> Void in
view.center = endPoint
}, completion: { (finished) -> Void in
view.dragState = MKAnnotationViewDragState.Dragging;
})
}
else if (newState == MKAnnotationViewDragState.Ending || newState == MKAnnotationViewDragState.Canceling)
{
var endPoint = CGPointMake(view.center.x,view.center.y - liftValue);
UIView.animateWithDuration(0.2, animations: { () -> Void in
view.center = endPoint
}, completion: { (finished) -> Void in
endPoint = CGPointMake(view.center.x, view.center.y + liftValue)
UIView.animateWithDuration(0.1, animations: { () -> Void in
view.center = endPoint
}, completion: { (finished2) -> Void in
view.dragState = MKAnnotationViewDragState.None;
})
})
}
}
My annotation:
var myPersonalView:MKAnnotationView?
myPersonalView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if (myPersonalView == nil)
{
myPersonalView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
myPersonalView!.canShowCallout = true
myPersonalView!.draggable = true
}
Litchy
Aucun commentaire:
Enregistrer un commentaire