iOS touch event triggering by movement of other view - ios

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.

Related

Drag MapBox map on different UIView (iOS)

Our UIView contains a MapBox map. At certain moments during our apps lifespan we display a UIView on top of the Map.
This view had a transparant background and a couple of controls inside it. What we want is to be able to drag the map on the spots where the view is transparent. (It should basically pass through the gestures to the view below it..which is the map).
To get a basic picture of what we try to accomplish: think of a map and above it is a view which shows a big + sign. What we want is when we drag the actual sign...nothing happens. But when you drag in the empty corners, it should drag the map.
Any ideas how to accomplish that?
Check out -[UIView userInteractionEnabled] and set it to NO for the transparent view. Be sure to set it to YES for the control subviews. That should do the trick.

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.

How can I modify the Android Gesture visuals (for on screen gesture detection)?

Essentially what I'm trying to do is use this gesture functionality as demonstrated below
https://www.youtube.com/watch?v=tG3lzBDMRQQ
http://www.vogella.com/articles/AndroidGestures/article.html
Except instead of just setting a color, I want to be able to add a variety of visual effects to the lines drawn during a gesture motion.
IE: pulsating thickness / color changing / particle effects like a sparkler-stick firework etc.
Where would one start in attempting such a venture?
edit: One method I'm considering is to set the gesture color to transparent, but have a separate listener for touches as in some paint-type apps. And So it simultaneously creatures the gesture and draws the proper image over top of it. Would this work? Can the screen be listening for input from two views at once?
GestureOverlayView is a normal view which has the capability to draw on screen. You can simply extend GestureOverlayView and add your custom effects. You can set your custom paint style, or you can override dispatchTouchEvent() to add your own effects while drawing it.

Draw animations dynamically (interactively) on MKMapView

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.

How to make an UIAlertView pop up when a bouncing image touches a draggable image?

How can I pop up alert when an bouncing image touches a draggable image the same way it's done in this app: http://tinyurl.com/kspnh6
Example: there is an image that is going up and down the screen and it touches an image that we can drag around. How can we show an alert view when that image touches the moving image?
When you move the dragged view around, check the updated frame property against that of the other items.
You can use a function such as CGRectIntersectsRect to determine if the frame of any two views overlap each other (i.e. when it's time to show the alert).
This acheives a rectangular "hit test", there would be more work involved if you wanted the hit test to respect rounded shapes etc.

Resources