How to increase MKMarkerAnnotationView touch and drag area? - ios

I show MKMarkerAnnotationView annotations on a MKMapView. When selected they can be dragged / moved by long pressing and then moving the annotation. This is how an annotation looks like when selected:
To start the dragging the user has to tap and hold until the annotation switches into the dragging state. All this functionality is provided by MapKit.
The issue: The user has to tap and hold right at the bottom of the red bubble to start the dragging process. If he tries to do that somewhere at the top of the bubble it does not work. This is very annoying for users of the app because they do not understand why dragging does not work. They expect the whole bubble area to be touch sensitive for the drag gesture.
How can I increase the touch sensitive area for the tap and hold => drag gesture to make it more intuitive?

Related

fix a MKPointAnnotation to centre of map (MapKit) even while user is scrolling

I need to fix an MKPointAnnotation to the center of the map even while the user is scrolling the map, it should still stay in middle. just like Ola app
By far I achieved searching, setting annotation to the center of the map and changing annotation to center again when user scrolls
however it updates when the user stops scrolling, but I want it to stay in the middle always so the user can scroll to an exact location.

MKMapView Swift : MKPointPointAnnotation Centre of screen

I'm trying to build a location selector in swift. The idea is :
When the map appears, an annotation pin appears at the user location. Then the user can change the location of the pin by moving the map around. (the pin stays at the centre of the screen. Like the uber app).
I have no issue spawning an annotation at the user location when the map loads. But I can't find a way to keep the pin at the centre of the screen when the user moves the map around.
I believe I must use regiondidChangeAnimated function, but I can`t find a way to update smoothly the position of the annotation.
Thank you for your help !
When you want some view to not move when you pan the map, just put it on the map view's superview (e.g. add a UIImageView to that superview), add the necessary constraints so that it's centered where you want it, and make sure that user interaction is disabled with that image view. Then you can pan the map and the image view will gracefully float there, above the map, not moving at all.

Detecting tap anywhere on widget?

I am trying to detect when a user taps anywhere within my Today Extension widget.
Currently I have a tap gesture recognizer on the primary view which contains all the labels displayed within the widget. However, with this configuration, only taps on the individual labels contained within the view are detected. If a tap occurs within the view, but not on a visible label, the tap does not appear to be detected.
I know this has to do with tap detection not occurring on any visual object that has less than 100% opacity. Unfortunately I cannot figure out how to detect taps on anything that isn't an opaque visual object.
Is there any way to simply detect a tap anywhere within the widgets bounds, including negative space?
Thanks!
Ended up just putting a view that covered the entire background of the widget's container.
Setting the view's fill opacity and the view's opacity itself both to .1% made it effectively invisible while still capturing taps.
:P

Tracking MKMapView centerCoordinate while panning

I'm implementing a map feature in my app where I allow the user to set their current location by panning around.
All this time, I want to have an MKAnnotation in the centerCoordinate. So what I want to do is keep track of when the map's centerCoordinate changes and change the annotation's coordinate correctly. The behaviour would be similar to that of Uber, Hailo and others.
I tried a time based implementation where every 0.00001s the centerCoordinate would be checked and the annotation would also be moved. But if the map isn't flicked gently, the annotation jumps from one place to another which doesn't make for a good UI.
Another implementation I tried is by way of gesture recognisers and the delegate methods of MKMapView (regionDidChange/regionWillChange). This, again, makes for a very abrupt transition.
Can anyone please advise me on how to do this better?
I suggest not using an actual id<MKAnnotation> at all (at least for this "current location setting" mode).
Instead:
Add a view (eg. UIImageView) containing an image of a pin (or whatever icon you like) in front of the map view.
This pin view should not be a subview of the map view.
The pin view should be a subview of the same view that the map view is a subview of (eg. both should be subviews of the same superview).
The pin view should be sized and positioned such that it appears above the center of the map view (you could make the pin view have the same frame and the same autolayout/autoresizing logic as the map view so they stay visually synchronized regardless of screen size or orientation).
If using a UIImageView, set its content mode to "center" and background color to "clear" (default is clear).
The pin view should have user interaction disabled on it so that the user can still interact with the map view behind it. As the user pans or zooms the map view, the pin view in front will seem to move instantly.
If necessary, the app can get the location coordinates from mapView.centerCoordinate in the regionDidChangeAnimated: MKMapViewDelegate method (or pan/pinch gesture recognizers) or only when the user says they're done positioning. I don't recommend using a timer (especially every 0.00001s) to query the current center coordinate.
When the user indicates that the current position is where they want to finally place the annotation, you can then create and add an actual annotation at that coordinate and hide the "location setting mode" pin view.

Emulate iOS zoom tool in Safari/Mail etc

I have a full screen UIView that is the application's main view that the user interacts with. The user is allowed to slide their finger across the view, and I need to zoom the area around a user's finger. Somewhat similar effect to the text entry fields in most iOS apps where if you tap, hold and slide your finger, the text around your finger zooms.
Any thoughts?
There is an open source control that does exactly that: https://github.com/acoomans/iOS-MagnifyingGlass

Resources