UITableView touch position or several gestures at a time - ios

I have UITableView, and added the ability for moving cells.
http://s017.radikal.ru/i402/1503/76/3442a9517cec.png
So, if longPressGesture is recognized, i make the cell hidden, take a snapshot of cell(on picture highlighted with grey), and change it's position while longPressGestureStateChanged. But the animation of moving looks bad.
If I add panGesture while longPressGestureBegan, it doesn't work until I touch up and touch down again, and after that panGestureStateChanged begin working, and moving become smooth.
I need panGesture begin working while longPressGestureBegan, or catch the screen touch position.
But the difficulty is: (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; etc... doesn't work on UITableView.
I read a lot, but nothing was founded. This is the custom case. I need for example to recognize pinchGesture only when longPressGesture was recognized, without touching up.
Anybody know how to solve this?

For UITableView use ready methods to move cells. You can find more information in the documentation.

Related

iOS: Calling Pan Gesture attached to a UIButton programmatically

When a user highlights a button in my horizontal scrollView, an identical looking button (Different draggable subclass) is added right above. What I'm trying to achieve is similar to lifting a card off a stack like Solitaire, and having another card underneath it.
Everything is working except that right now the moment the user highlights, the touch get's canceled as the new view come's into place. The user has to lift their finger off and tap again to register that the dragging event has begin. What I want to do is to automatically pass the touch from the first button to the newly added button without the user having to remove their finger again and touching the new button. I'm not even sure if this is possible.
Maybe I'm thinking about this the wrong way, but the reason I don't make the first button the draggable button is because I reuse it in my horizontal scrollView.
Which I feel you should consider each card as a custom UIView and handle
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
to show selection, dragging and finally placing of a card. So all logic for selection and put card would in one custom UIView class. For all other validation do that in your parent UIViewController

Subclassing UIControl's endTracking for multitouch

I'm creating a custom control* by subclassing UIControl and overriding the following methods:
- beginTrackingWithTouch:withEvent:
- continueTrackingWithTouch:withEvent:
- endTrackingWithTouch:withEvent:
- cancelTrackingWithEvent:
This control will support multitouch interaction. Specifically, one or two fingers may touch down, drag for some duration, and then touch up, all independently.
My issue comes at the end of these multitouch events, in endTrackingWithTouch:withEvent:. The system calls this method on my control exactly once per multitouch sequence, and it is called on the first touch up that occurs. This means that the second touch, which could still be dragging, will no longer be tracked.
This sequence of actions serves as an example for this phenomenon:
Finger A touches down. beginTracking is called.
Finger A drags around. continueTracking is called repeatedly to update my control.
Finger B touches down. beginTracking is called.
Fingers A and B drag around. continueTracking is called repeatedly to update my control.
Finger B touches up. endTracking is called.
Finger A drags around. No methods are called.
Finger A touches up. No methods are called.
The issue lies in the final three steps in this sequence. The documentation for UIControl says the following of endTrackingWithTouch:withEvent::
Sent to the control when the last touch for the given event completely ends, telling it to stop tracking.
Yet it seems to me that after finger B touches up in step 5, above, the last touch for the given event has not yet completely ended. That last touch is finger A!
*A range slider, if you must ask. But there are already plenty of open source range sliders, you say. Yes, true, but this one will support multitouch and Auto Layout.
I had the same issue in custom control with multitouch.
Because UIControl is subclass of UIView that inherits from UIResponder, so feel free to use:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
methods.
These methods work fine in UIControl subclass.

touchesBegan: withEvent: is not called when tapped on a UIButton

What I want to implement is column matching type functionality. I have three buttons on right column and three on left column with some info on them. I want to draw path from one button on right side to any of the button on left side by dragging finger.
I would use UIBezierPath path to draw path, and for that definitely a start and end point is needed.
Now the issue is how can I trigger touchesBegan, touchesMoved and touchesEnded methods by tapping on buttons so that I can get start and end points.
Another option that I am thinking about is to cover all the buttons with an invisible UIView, and somehow check if the point touched of this overlay view lies in any of the button frames.
BTW I can replace these buttons with simple UIImageView as well. I added buttons just for the sake of getting touch points.
Any help.
Create a subclass of UIButton and add this...
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
}
This will get you your touches within the button.
Uncheck User Interaction Enabled checkbox of UIButton. You will get call for touchesbegan method on that button.

UIGestureRecognizer: difficult to tap moving objects

I have an xcode iOS project I'm working on where I have falling particles coming from the top of the screen down to the bottom. Based on the accelerometer, they can either fall fast, or slow.
They are all UIImageViews that are falling, and when I tap them, they should just stop moving. This works fine if they are moving slow enough and I seem to tap just a little bit under them. The problem with this is that when I tap right on top of them when they are moving fast, I can never seem to hit them.
What's the solution to this? Do I need to make a bigger UIImageView with a smaller UIImage centered in it? Or can I use the UIGestureRecognizer to look for taps in a larger radius?
Try using UITapGestureRecognizer
(or)
Try to catch the touch event using touchesBegan: method.
Try writing the touchesBegan: method as follows:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
if (touch.view == UIImageView)
{
// execute the code you need to stop the UIImageView from moving
}
}
Hope this helps. All the best with your app :-)

UIView touchesMoved not called if first finger released

I want to achieve a simple task - detect up to 10 touches in a UIView.
Using these:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
It all works great.
Problem is - touchesMoved:: is no more called - if first finger, that touched screen no longer touches screen.
Is it possible to fix it? (so that - while atleast one finger from 10 fingers is still touching screen - touchesMoved:: would be called?
If it is not possible in UIKit, could it be possible in Cocos2d, and how? (some links, function peaces would be really helpful)
You probably just need to set theView.multipleTouchEnabled.

Resources