Draw animations dynamically (interactively) on MKMapView - ios

I want to draw an animation over MKMapView. I want it to be something like a compass arrow, that follows (rotates) user's taps / swipes .
So the arrow goes from the center of the screen and is of a fixed length. I don't need the line to be coordinate-specific, but I need to keep the map interactions intact (i.e. still being able to pinch-zoom on the map).
I tried to do that via MKPolyline (creating and then destroying a line), but that does not work (and from the way I had to do that I feel like it won't work). I wonder what would be the best way to handle that? Quartz?
I would accept just an explanation (which kind of view overlay over what, which classes to use), no code is necessary (but if you have a working example that's so much better ))

I draw views like a map ruler not as subview from MkMapView. I put kMapView and my ruler view into a container view. This works for views which positions are fixed on screen, like on center of screen, and are not related to a geographical position.

Related

How do I add an overlay that does not move with the map to a GMSMapView?

I'm trying add a crosshair in the middle of a GMSMapView. The crosshair will not move with the map as the user pans it. It will move with the camera.
I looked at the google maps guide but it doesn't seem to talk about the kind of overlays I'm interested in. What it says is just adding overlays and shapes that moves with the map.
Therefore, I tried to come up with something on my own. I tried to add an UIImageView on top of the map view he storyboard. (Note that both the image view and the map view is in the storyboard and they are both direct subviews of the view that the VC controls)
When I run the app, I did not see the crosshair anywhere on the map. I looked at the UI hierarchy and saw this:
The little view is the image view with the crosshair, and as you can see there are 3 more views in front of it. I think this is why the crosshair did not show. The three views are, from right to left: GMSVectorMapView, GMSUISettingsPaddingView and GMSUISettingsView.
I have not idea how to bring the image view to front. I tried bring it to front by calling bringSubview(toFront:). I tried to call this in both viewDidLoad and viewDidAppear but it did nothing in both times.
How can I make such an overlay work?
You can use zPosition to achieve this
YourView.layer.zPosition = 1
by doing this you will put your view's layer to the frontmost position, but not the view itself. So position of the view won't change.
self.view.bringSubview(toFront: YourView)
Should also work, it's probably juat a timing problem.

iOS touch event triggering by movement of other view

Here's the scenario I am trying to implement:
I already have a view that can let user draw doodles by touching inside the view directly (like a doodle canvas). This view implements touchesBegan, touchMoved, and touchEnded handlers to draw lines from touch event parameters.
Now instead of that, I want user to be able to drag and move another UIView on this canvas view and can still draw lines just like they touch directly. For example, user can drag a pen image view on the canvas view to draw pen-style lines.
In this case, how can I transfer the movement of this pen image view to the canvas so it recognize it? One more question: if I want this canvas view to only recognize movements of drag other views rather than touching directly, what I should do?
(Sorry that this question is little too general, just want to get some pointer of it)... Thanks!
A better way to look at the problem is
How can I transfer movement on the canvas into the location of a pen
image view?
That's easy. You already have all the code that keeps track of movement in the canvas (touchesBegan, touchesMoved, touchesEnded), so all you need to do is change to center property of the pen view to track the movement in the canvas. (Obviously, you'll need to apply small X and Y offsets to put the center of the pen view at the correct location).
The only non-obvious detail that you need to be aware of is that the pen view must have userInteractionEnabled set to NO. That way, the pen view won't interfere with touches reaching the canvas view.
Note that UIImageView has user interaction disabled by default, so you don't need to do anything if the pen view is a UIImageView. However, if you're using a generic UIView to display the pen, then you need to disable user interaction in storyboard under the Attributes inspector or disable it in code, e.g. in viewDidLoad.

Touch sensor for a line drawn in IOS

I have a requirement to draw a line on a UIView in IOS with OpenGL ES. But the line that is drawn could be able to move anywhere on the view when it is touched and dragged. Simply the user can re-position the line on the screen. I have no idea how this can be implemented. The line will be drawn with OpenGL ES.
I request all your helps and suggestions regarding this.
The solution is to use a second transparent view positioned over the OpenGL view, which acts as a proxy to your line.
Create a clear view (or a view with 0.0001 opacity) and add gesture recognizers to it. Initially place that view (say sized to 44 x 320), and centered over your line (I'm assuming its horizontal). When the user drags the clear view around, post the new position you want your line to appear in within the OpenGL view then tell it to refresh.
I seem to recall (but am unsure) if you can use gesture recognizers with completely clear views - you may need to make the view slightly opaque (but no visibly so) to get touches, but again just not sure.

Rotating the content of a RMMapView

i'm working on a app using the route-me project. I'd like to have a mapView rotating to fit with the current heading. I kwow that the issue has already been dealt with.
Therefore, when is use
[self.mapView.contents setRotation:desiredAngle];
or
[self.mapView setTransform:CGAffineTransformMakeRotation(desiredAngle)];
on a RMMapview i put on the detailViewController of a SplitViewController, i get a weird behavior.
it's the view that rotates and not the map contained in it. Graphically it means that the square containing the map rotates and we can see white area where the square's corners were formerly.
Can someone help me solve this issue or explain me what i didn't get right in the first place.
Thanks
Apparently setting the mapView's width and heigth equal to the diagonal of the containing View solves this issue.
To understand why we just have to think about the view behavior and figure out that the white areas that appear wouldn't if we took a bigger square for the view's frame.
To sum up, your mapView must be big enough to hide its (actual) corners from the user's sight.
Not really a solution, more a workaround but it's enough for me.
Hope it helps

Drag/Swipe to scroll the screen

What would be the best way to have a vertical scrolling screen? My game will consume two screens high, the user should be able to move between the two screens by a simple drag or swipe action. The background is not tiled and sprites will be placed on it. What would be the best way to go about such screen management?
You have asked two questions here. The fist of which is how to respond to touch gestures (like a swipe). This blog post and associated sample is a good starting point.
The second of which is how to have two screens. This is also simple. Pass a translation matrix (Matrix.CreateTranslate) into SpriteBatch.Begin. How you want to do this is up to you. If you want both screens to have (0,0) be the top left of the screen, give each of them a translation matrix and translate one downwards by the display's height below the other. (While a screen is out of view, you could skip drawing it entirely.)
When the user swipes, simply animate the translation such that one screen moves out of view, and the other moves into view.
It depends on whether you want users to be able to see half of the top and half of the bottom screen, or only ever the top or the bottom.
You could try placing the two screens worth of content into a ScrollViewer, and setting the ScrollViewer.VerticalScrollbarVisibility to False; this would allow users to drag/swipe easily between the "screens".
Something like:
<ScrollViewer VerticalScrollBarVisibility="Hidden">
<my:FirstScreen/>
<my:SecondtScreen/>
</ScrollViewer>
One thing to consider would be whether you want to handle the user changing the phone orientation, or whether you'll lock the phone into Portrait/Horizontal orientations. I also believe that phones with different resolutions will eventually be released and any applications in the Windows Marketplace will need to be able to handle both full and half resolutions.

Resources