Affects non-UIView methods hosted inside a UIScrollView

I have a custom scroll subclass of UIScrollView . I added scrolling in the ncontroller viewcontroller file and changed its class to CustomScrollView. Now this custom scroll view (made from xib) is added as a subview on self.view.

In this scroll view, I have 3 text fields and 1 UIImageView (named signImageView) added from xib. When UIImageView (added by TapGestureRecogniser ), a UIView named signView is added to the user scroll. I want to allow the user to sign this view, so I created the Signature.m and .h class, subclassing the UIView and implementing the touch methods (touchhesBegan, touchhesMoved and touchesEnded) and initialized signView as follows:

 signView = [[Signature alloc]initWithFrame:signImageView.frame]; [customScrollView addSubview:signView]; 

But when I start subscribing to signView, the view scrolls, and so the touch methods are not called.

I tried adding signView to self.view instead of a custom scroll view, but in this case, the view remains stuck to a fixed position when I start scrolling. (In this case, its frame remains fixed)

+4
source share
3 answers

Try setting canCancelContentTouches from scrollView to NO and delaysContentTouches to YES .

EDIT:

I see that the same question was answered by Drag and Drop using Cocoa on the iPhone (the answer is exactly the same).

If the tap-n user holds signView (approximately 0.3-0.5 seconds), then viewing the touchesBegan: method touchesBegan: triggered, and all events from that moment go into signView until touchesEnded: is called.

If the user quickly wades through signView , then UIScrollView takes over.

Since you already have a UIView with a subclass with the touchesBegan: method implemented touchesBegan: maybe you could somehow tell the user that your application is prepared for signing (equivalent to green light).

You can also use touchesEnded: to turn off this green light.

It might be better to add signImageView as a subView from signView (instead of customScrollView ) and hide it when touchesBegan: run. You would signView to customScrollView in the same place where you are adding signImageView to existing code instead.

With this, you achieve that only one subView effective at that place (for better touch efficiency. And you could achieve this green light effect without hiding signImageView in touchesBegan:/touchesEnded:

If this application behavior (delay 0.3-0.5 s) is unacceptable, you will also need to subclass UIScrollView . There may come to the aid of the Vignesh method of overriding UIScrollView touchesShouldBegin: There you can find that the touch touched in signView and immediately passed it to this view.

+7
source

When you add scrolling to your view hierarchy, it swallows all touches. If you do not start to roll. Thus, in order to get the touches in the presentation of your single, you will have to convey touches to the presentation of the singles. This is how you do it.

+3
source

We accomplished this with a subclass of UIScrollView that disables the panorama gesture recognizer for the list of views that you provide.

 class PanGestureSelectiveScrollView: UIScrollView { var disablePanOnViews: [UIView]? override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { guard let disablePanOnViews = disablePanOnViews else { return super.gestureRecognizerShouldBegin(gestureRecognizer) } let touchPoint = gestureRecognizer.location(in: self) let isTouchingAnyDisablingView = disablePanOnViews.first { $0.frame.contains(touchPoint) } != nil if gestureRecognizer === panGestureRecognizer && isTouchingAnyDisablingView { return false } return true } } 
0
source

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


All Articles