Raise the Crane event with the UIScrollView subzone when scrolling

I have a custom subclass of UIScrollView with some content views inside. In some of them I have a UITapGestureRecogniser. Everything works fine when scrolling does not scroll. But when scrolling the content views does not take the action of clicking. What is the easiest solution to handle the action of a tap view while scrolling scrolls?

Details:

MyScrollView scrolls horizontally. It contains many representations of content (e.g. MyContentView ). Each MyContentView is about one third the width of the MyScrollView . Thus, at the moment there are about 3-4 visible MyContentView elements. The main behavior of MyScrollView is 1) make sure that after scrolling one of the MyContentView elements will be in the center of the screen and 2) to scroll to the center of MyContentView if the user clicks on it . Therefore, the main answer that I hope to get is to "correctly" implement the processing of the crane action in MyContentView , and MyScrollView slows down.

I found several questions and answers, but none of them satisfied me. The best thing was to implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: delegate of UITapGestureRecogniser. But in this case, sometimes (when I press, I do a smaaaal drag and unlock my finger so that the tap becomes recognizable (lets call it a quasi-multiple tap)) I have both click and scroll events, and this leads to errors for me, even if Scrolling does not scroll when I start the tap. When the user makes a quasi-red click, my application tries to scroll the tapped MyContentView element and handle the normal scroll immediately. It seems even more scary, due to the fact that some other functions begin to perform after accessing the tap (it should not be performed during normal scrolling).

I need a solution in which the scroll view came up enough to decide that this is not a click event, and only then scroll. Otherwise, if the transition event is not recognized, there should be no scrolling.

+6
source share
2 answers

You can also use special delegate methods using @protocol . Add these delegate methods to the view controller where your UIScrollView is added.

as in MyContentView :

In the touchsBegan method

 [self.delegate contentViewTapped:self]; 

Now in the ContainerView class where scroll view is added, execute this method:

  - (void)contentViewTapped:(MyContentView *)myContentView { NSLog (@"ContentView no: %d", myContentView.tag); // if tag has been set while adding this view to scrollview. } 

Go through the examples for @protocol .

Hope this is what you need.

Enjoy the coding :)

+5
source

This is built into the UIScrollView - take a look at the delaysContentTouches and canCancelContentTouches . This should alleviate the problem of dragging a small bit after clicking.

This is all system built-in behavior. I would advise you to stick with what Apple has provided for the perception of your interface (for example, how it reacts to small drags), so that your application does not feel out of place on a user phone.

EDIT:

Alternatively, you can disable the scrolling of your scroll in your gesture recognizer and enable it again after it is completed / canceled.

Further editing: I don’t understand - I created a sample project that illustrates how to intercept touches in the scroll pod using the gesture recognizer delegation methods. Pay close attention to the “Cancel access to content” and “Hold content bindings” properties in the scroll view. They are both YES for very important reasons.

Scrolling in the view should delay the content until it determines whether the user is trying to press the red button, the pseudo-drive (as you put it), or the panorama to view the scroll. Apple has already written the functionality you are trying to build; UIScrollView will already do what you want.

The problem is that the system does not want the scroll view routines to catch short press events when the scroll is viewed. To this end, it cancels touch events if it determines that the user is actually trying to pan. The setting "Delays when submitting content" allows this behavior. Make sure it is turned on and everything will be in order.

+4
source

Source: https://habr.com/ru/post/921195/


All Articles