Intercepting touches on MKOverlay border - ios

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.

Related

Make a Mapbox RMAnnotation display its callout programmatically

I'm making an iOS app (using Swift) that has a map in the Mapbox iOS SDK. I've gotten to the point of displaying several markers on the map. Now, I want the user to be able to select a marker from the list, panning to that marker (easy), which also makes the marker's callout bubble appear automatically without the user having to touch it (not so easy).
It's this last task I'm having trouble with. While I've found the RMMarker class's showLabel() method, I can't seem to directly access a RMAnnotation's associated RMMarker object, so I'm not sure where or how to call this method.
Does anyone know how this is done?
Ignore the showLabel() API — this is not the callout in use, but rather a text label that's possible directly on the annotation.
You probably want -[RMMapView selectAnnotation:animated:] with a NO in the animated argument.

Create Custom shaped button using CALayer

what is the best way to achieve the following.
Basically what I want to do is to create an "intractable area" where the user can touch and subsequent actions will take place. For example in the picture the user taps the green area a pop is presented with some options. Similarly there would be different colour "intractable areas or buttons" with in that pizza slice, if you may.
I was thinking of having buttons created through CALayer and try to fit them with in the bounds of the empty state image, but i don't know how to achieve this. Any other ideas are well appreciated.
I would subclass UIButton or UIControl to make your custom button. Then override pointInside:withEvent: to see if the touch event is within the correct region.
See these links for more info and ideas:
Non-Rectangular Buttons on iOS
Abusing UIView (see section on pointInside:withEvent:)
How to create a transparent window with non-rectangular buttons?
iPhone button with non-rectangle shape?
OBShapedButton

drawing on UIView in iOS

I am developing iPhone application and I have taken UIView and I want to draw particular region on view on user touchMove event. So please can anybody suggest to me how to do it means how to implement the touchMove event so it can draw region concurrently with user touchMove.
What you need to do is:
Create subclass of UIView.
Implement all the touch methods like
touchesBegan:, touchesMoved:, etc.
Use drawRect:,
UIGraphicsBeginImageContextWithOptions and UIBezierPath to draw
image based on touch locations.
There are many tutorials on the internet. I find this one quite good: Advanced Freehand Drawing Techniques

Click on MKPolygonView

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.

Adding Custom Image on Mkannotationview, or on callout bubble?

i'm trying to reproduce the kind of map behavior of the app "Stuck On Earth". Here's a screenshot :
Here's the behavior :
On the map, as you can see there is pin
When you click on a pin, it display the picture attach to it. Really important : the picture stai with the pin, and it stays BEHIND it
If you click on the picture, a new controller is called
if you click on the pin, the picture disappear
I'm trying to do something similar. For now, as i can read, i've got two solutions :
Using callout : callout is HELL. I can try to use a false annotation, but MapKit deals with the depth of elements, and the picture is always in front of the pin
Using Custom Annotation : i was going for the plan of making custom annotation view, when the pin is tapped, i launch a method of the CustomAnnotationView, adding (or removing) the thumbnail.
I think the method number 2 could work, but i've got no idea how to deal with the touch on the thumbnail.
Any suggestions or help on this ?
Thanks you !
Updated 2016-09-02:
My colleague devised an workaround by making popup views as subview of the view container which contains the map view. The position can be calculated according to the CGPoint transform in different reference systems.
Original Answer:
I also got this kind of problem, after following the tutorial 'Building Custom Map Annotation Callouts – Part 1', the interaction becomes difficult.
Have you tried the tap gesture recognizer? I added it to a subview, it works, although the code smell bad.

Resources