Detection if the user has moved the card, or if it happened programmatically. Ios mapkit

So, I have a map loaded with pins from a remote JSON channel that is loading into the application. All of this works great.

Now, from the initial experiment, regionDidChangeAnimated is called several times, so I moved my mail request to a method that uses a drag and drop card gesture recognizer, which then performs a mail request to get data from the JSON channel and reload my card contacts after deleting them. This also works great.

Now, the only problem I am facing is that if I select an annotation close to the edge of the screen, the map will move slightly to display the annotation leader. The problem is that regionDidChangeAnimated is called when this happens, but my mail request does not work, as I call it, using a gesture recognizer, and therefore the map was not moved by user intervention, but by the OS. I don’t want to move my send request to regionDidChangeAnimated , as this has been called several times, but I would like to know if there is a way to do the test if the user made the card move or did it by itself to adjust the leader, as described above. regionDidChangeAnimated from the study I looked at may get more time than necessary, so some recommendations will be useful in how to prevent this or to detect user interaction with the OS moving the map.

+4
source share
2 answers

I have a similar problem: I want to distinguish whether the changed part of the map was changed by a program or user interaction. Apparently MKMapView objects MKMapView n't tell me about this, i.e. regionDidChangeAnimated is called in both cases without specifying a reason. But since MKMapView is a subclass of UIView , and this is one of the UIResponder , you can implement the touchesBegan:withEvent: and touchesEnded:withEvent: to find out if the display was affected when the displayed area was changed.
If so, it can be assumed that the change in the displayed area was caused by user interaction. Of course, you can be more specific if you study the set of touches and the event type of these methods more precisely.

+2
source

I am such a tablet that can sometimes help in writing problems. I just deleted the regionDidChangeAnimated, since I didn’t need it, and the code that was there, I switched to my gesture, which should have deleted the Annotations before adding their doh again!

0
source

All Articles