Click on MKPolygonView - ios

I have created severals MKPolygonView's on MKMapkView.
Now I want to recognize when a polygon was touched on the map. Also mark that polygon with other color.
I have one solution to do this with a longpress handler. This isn't the best solution.
Is there another easy way to do this?

Yes use UILongPressGestureRecogniger, all gesture recognizers are easy and convenient to use.

Related

Make mapbox annotations draggable as soon as they are added to the map

I have successfully managed to implement draggable annotations by using this link https://docs.mapbox.com/ios/maps/examples/draggable-views/. However, these annotations become draggable only after long pressing on them. I am looking for a solution wherein the annotations become draggable as soon as they are added to the map. Thanks a lot for helping :)
Ended up coming up with my own implementation to suit my needs. Heres how I went about it:-
Add the UIPanGestureRecognizer on the annotation view of the annotation that needs to be dragged.
In the gesture recognizer, convert the in-screen gesture location to real-world coordinates using the mapView.convert(point, mapView) method. Use these coordinates to update the location of the dragged coordinate
Use the started and the ended state property of the gesture recognizer to determine the start and end of the drag gesture.

Detect touch screen in iOS

Now I have implemented the fling feature in my ios app, but I want to stop the fling when a touch on screen happens, this does not only contain tap gesture, maybe other like long press or pinch, I have a BOOL value to indicate whether a touch happens, so should I add all kinds of gesture recognizers and set to BOOL value as true? Are there any simple solution? Thank you!
There are several methods in UIGestureRecognizerDelegate that will achieve what you want. gestureRecognizerShouldRegognizeSimultaneouslyWithGesture sounds like the best candidate. You will get passed two gesture recognizers. One will be your swipe gesture (the one you want to keep), the other will be the one you want to cancel (tap, long press, pinch) return NO in the correct scenario.
See docs: https://developer.apple.com/documentation/uikit/uigesturerecognizerdelegate

iOS drag and drop images

I was trying show a bunch of images, one at once. User could swipe left or right to navigate, just like photo library.
What I did is, for example I have 6 images, create a scroll view to hold those 6 images, and using pan gesture to move it.
Am I doing right? Or is there another neat solution?
Thanks
EDIT:
I'm asking am I doing right by using gesture?
More specific, should I use UIScrollView to do this or I should use something else?
Update:
I finally figure out a way to do. Use UIPanGestureRecognizer and check the speed. if the speed is fast enough, then treat like swipe gesture. Will post code later.
UIScrollView has a default gesture and does not need a new one.

Intercepting touches on MKOverlay border

One of the functions of program is to select a piece of the map. I do this using MKAnnotations and using a MKPolygonView (with just the border visible) to connect the "dots". (Please take a look at the screenshot below).
However, I'm trying to find a mechanism so that users can add new pins. This should be done by pressing on a border part of the MKPolygonView and then a new pin is added in the middle of the border.
In order to do this, I have to intercept touches, probably using the UIGestureRecognizer. I have looked at Touch events on MKMapView's overlays, which gave me a good lead. The only problem is that this intercepts touches also inside the MKPolygonView. I just need the border.
Is there any way to achieve this kind of behavior?
This is an old question, but anyway - one of the possible workarounds is using MKPolyline simultaneously. You could add a MKPolyline, matching MKPolygon border and detect taps on MKPolyline.

How do I implement multitouch on iOS

I'd like to implement multitouch, and I was hoping to get some sanity checks from the brilliant folks here. :)
From what I can tell, my strategy to detect and track multitouch is going to be to use the touchesBegan _Moved and _Ended methods and use the allTouches method of the event parameter to get visibility on all relevant touches at any particular time.
I was thinking I'd essentially use the previousLocationInView as a way of linking touches that come in with my new events with the currently active touches, i.e. if there is a touchBegan for one that is at x,y = 10,14, then I can use the previous location of a touch in the next message to know which one this new touch is tied to as a way of keeping track of one finger's continuous motion etc. Does this make sense? If it does make sense, is there a better way to do it? I cannot hold onto UITouch or UIEvent pointers as a way of identifying touches with previous touches, so I cannot go that route. All I can think to do is tie them together via their previouslocationInView value (and to know which are 'new' touches).
You might want to take a look at gesture recognizers. From Apple's docs,
You could implement the touch-event handling code to recognize and handle these gestures, but that code would be complex, possibly buggy, and take some time to write. Alternatively, you could simplify the interpretation and handling of common gestures by using one of the gesture recognizer classes introduced in iOS 3.2. To use a gesture recognizer, you instantiate it, attach it to the view receiving touches, configure it, and assign it an action selector and a target object. When the gesture recognizer recognizes its gesture, it sends an action message to the target, allowing the target to respond to the gesture.
See the article on Gesture Recognizers and specifically the section titled "Creating Custom Gesture Recognizers." You will need an Apple Developer Center account to access this.

Resources