touchesBegan and ended in collection view - ios

I am trying to have a view with a frame on the cell in a UICollectionView from the second a user taps.
The function I want it to have is:
Appear when touches begins in a cell, touchesBegan?
If the touch is a single tap, tell me so I can handle
If the touch is a long press, tell me so I can handle
If user moves finger while down, move frame.
Right now, i'm adding the frame as an image in a UIImageView in a UICollectionViewCell on a gesture recogniser i've added for longpress. Single tap is detected with standard UICollectionView delegate methods.
Any ideas on how I could accomplish this? I don't know about any methods for cancling touchesBegan/Ended on single tap etc...

Maybe this will help
UIResponder touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:

Related

UIView that expands with a gesture recognizer

I'd need to make a subview expandable as long as the user taps a finger on it and drags it down, and collapsed again to its initial size when the user releases it (is that a Pan gesture?)
I've been looking for an example for this, with no success. Could somebody tell me which should be the best way to implement that?

How to get event touch move of UIView when move finger from outside view

I have a UIView custom. In this UIView custom, I have a small UIImageView. When I move finger through it, it will move with my finger. To do that, I use UIPanGestureRecognizer (add this gesture to UIImageView). But when I move finger with begining point not in UIImageView, it will not handle this event.
So, my question is "How to get event touch move of UIView when move finger from outside view ?"
Thanks.
Best approach is create a uiview with necessary size(which is larger than uiimageview). Place the uiimageview inside it. Add gesture recognizer to uiview instead of uiimageview. In the delegate method of geature, move the image view.
There is a "Touch Drag Enter" Event which might be what you are looking for.

Cancel UIGestureRecognizer if subview contains gesture?

I was originally using the UITouch methods (touchesMoved: withEvent:) in order to detect the movement in a view. Due to the fact that it seemed not to update often enough I switched to using a UIPanGestureRecognizer (though this didn't actually fix the initial problem).
After using this the touches received for movements responded no matter what it was touching (different subviews) which I actually prefer. However now I have an issue with all the subviews which have movement. I need the gesture recognizer to still move the view even while touching subviews, however if the subview also moves in this direction (left/right) I need my recognizer to cancel.
It seems like gestureRecognizerShouldBegin: might be somewhere to start, but in my case, I cannot account for all subviews.
Is it possible to make pan gesture recognizer cancel if the subview (i.e. another pan recognizer, UISlider, horizontal scrollview, etc.) touched needs to be moved in left/right directions without having to account for each subview individually?

Disable scroll in UIScrollView while multi touching

In my program I use two fingers to pinch (zoom in and out), so sometimes when I want to pinch, app scrolls.
I would like to don't let scrolling in UIScrollView while two or more touches are on screen. How can I achieve that?
Try using UIGestureRecognizer.
In you case you must use a UITapGestureRecognizer, with 2 finger and one tap.
Attach the gesture on the table view.

How do I pass delayed scroll gestures from a UIButton inside of a UIScrollView?

I have a UIScrollView that contains several UIButtons. Each button is wired up to take an action when the user inputs a touch up event, so they are able to place their finger on the button and it will not be selected until it is raised. Currently, if I made a swipe gesture to scroll the UIScrollView quickly, then the scroll view moves as expected even if the gesture happens directly over a UIButton. HOWEVER, if I hold my finger down too long on a UIButton (about 1 second), the UIScrollView will no longer recognize the gesture and will not be able to scroll until the finger is lifted up.
I am wondering if their is a way to always have the UIScrollView recognize the scroll gesture? Note that this is not an issue if I touch the UiScrollView in a location without a UIButton - it then scrolls as expected.
It may worth a try to let your UIButton respond to UIControlEventTouchDown (maybe with an empty action). I'm not sure if this will work, but conceptually I think it should let the UIButton capture the touch immediately.
(Also make sure you don't enable delaysContentTouches on your scrollview.)
I found the answer to this here: UIScrollview with UIButtons - how to recreate springboard?
Essentially, I had to extend UIScrollView and override touchesShouldCancelInContentView, having it always return YES.

Resources