Handling touch events on UIImageViews - iphone

I have a UIImageView, above which I have multiple markers. All the markers are movable, i.e. when I touch a marker, I can move it all around the screen.
Problem: if I touch a marker, and I begin to move it to another place, if I cross another marker, the old marker is left in place of the new one, and I continue to move the new one. And I want to evade this somehow.
Thanks for the answer.

What are your markers? If they are UIView instances then I would suggest watching for touch events on them instead of the image view and then deal with the Z order while dragging.
I would also pay attention to touch up vs. touch moved to help with the issue of your stops and starts.
If they are not UIView instances then the issue sounds like it is with your touch down vs moved. i.e. you should keep track of what marker was touched on the down event and then ignore any events that hit another marker that are not down events until you get an up.
If these suggestions are not helpful then describing how you built your view structure would help.
Z-Order
When you receive a touch down event on a marker I would move it to the top of the z order of views within the parent. Then will allow it to visually slide over the other markers.

Related

How to shift the drag and drop feedback to the left?

I am building a chess board component, in which we should move the pieces by a simple Drag And Drop. In order to ease the drag and drop, I also try to draw a feedback which is a "cross of cells" centered around the pointer.
So, I am trying this way :
I draw a container that starts at the pointer location
Inside that container, I draw the entire cross, also drawing the dragged piece at the center of this container
So, I need a way to shift that feedback half to the left and to the top. That is, I need the feedback to be positionned to left and to the top of the pointer location.
Is that possible ?
I've tried playing with feedback and dragAnchor properties of Draggable, but I did not achieve.

How to prevent Scroll Box from consuming touch event in Unreal?

I am working on a UI system for a mobile game in Unreal. I have functionality already in place that basically reads in if the player has swiped by basically getting the player's initial touch location and then checking if the player moves their finger a certain pixel distance and then it changes between pages.
I am trying to add a scroll box to the page as I find that not all of my content will fit on the screen. However, now that I have added it to my Widget, my swiping function no longer works. I am assuming this is because the scroll box is consuming the touch event. Is there a way to make it so that the scrolling does not consume the input event?
I had the same problem but unfortunately, I couldn't find how to continue to read touch events.
As a workaround, I created my own scrollbox, so that I could read the finger location while I'm scrolling.

a touchable polygon on a view ?

I need to show a view on which I need to animate a polygon using its vertices. The polygon should be touchable, thus fire an event once touched, and I need to be able to move its vertices using some animation procedure, once it has fired that event.
I need to have three polygons like that to form a 3D Cube.
The darkened area is the view (actually an image) on which I have the cube.
There are two steps in the process: drawing and event handling.
Drawing can be done with Quartz2D, by implementing a drawRect in a view, calculating the coordinates of the cube on screen, followed by creating and drawing the path, which works fine for solidly filled shapes. The alternative method uses an OpenGL view where you specify triangles.
At the event handling end, you can implement onTouchesBegan: and friends to get the location of the interaction, and possibly hitTest: to allow other views below it to handle subsequent events. The next thing you will need to decide is how accurate you want to be - you can define a box that roughly matches the cube and test that for touches. Most people will want to touch it somewhere in the middle anyway. For accurate testing, you need the screen coordinates, and test each triangle in each polygon to see if it contains the location. Google turned up a nice explanation on the maths needed for that. In the OpenGL case, you'll have to manually repeat the calculations performed by OpenGL to find out where on screen your polygons have ended up.

NSImageView and NSUndoManager

I have a image on the view and user can drag and move the image or rotate the image with finger touch.
I want to do Undo the action performed by user.
Like if the image is move to new location and then user press undo button, image should move back to the previous location. Or if user rotates the image and then press undo button it should rotate image to its previous angle.
It would be helpful if I get any sample example for the same.
Thanks in advance
Check out the Solution that Rob Posted here.
It only deals with one gesture at a time though. If you are dealing strictly with the Transform and the Center (for Pan) then You should be fine with his solution if you do not allow Pan, Rotate, Pinch at the same time. If Pinch Pinch and Rotate at the same time, if working with a Transform you just need to set the transform once at the beginning and deal with who sets it first so the other gesture does not set the Original Transform.
I'm working on a way to encapsulate multiple attributes into a Dictionary to then Undo/Redo, though need a way to copy that Dictionary to the Undo/Redo Stack, see this Question

Moving a UIView along a CGPath according to touch position

I have a line graph I've drawn in Quartz, and a UIView 'bubble' that I'd like to ideally pop up when the user touches the single plot line, and moves their finger along it. The bubble displays some extra graph information.
I'd like to 'attach' the UIView to the CGPath plot, but I'm having trouble conceptually figuring out the best way to do this. I know you can animate a view along a CGPath, but this doesn't seem to work for me, because the user needs to 'scrub' along the graph themselves with their finger rather than any automatic animation.
Does anyone have any suggestions of a good approach?
Maybe you don't need to animate it. Touch events fly by pretty quickly -- maybe if you just move the view to the appropriate location relative to the touch without animation the move will be smooth enough. If that's not good enough, you'll have to animate along the graph segment from the current location of the view (see CALayer presentationLayer) to the desired location. The key is that you'll be animating every time you receive a touch event (and any previous animations would be cancelled).
Like Neil said, your best bet is to just move with the touch events, it will look smooth if all you're doing is moving a view. Use [aTouch locationInView:view] to get the touch's position, then find the closest point on the path (maybe use the x value and look up the y value on the path for the x).