UIScrollView and content with requires touch move

2019-06-27 20:22发布

问题:

I have a view which is using single touch events (single finger) for drawing (lines, cycles, text, and so on). Now I want to put this view inside of UIScrollView, which will allow zooming and panning. Of course two fingers are required to perform both zooming and panning.

What is the pattern do do that? I've found only examples when contents of UIScrollView accepts only single clicks (it contains only a buttons). Nothing what to do when contents require also touch moves.

回答1:

Access the panGestureRecognizer property on the UIScrollView, and set its minimumNumberOfTouches property to two:

myScrollView.panGestureRecognizer.minimumNumberOfTouchesRequired = 2;


回答2:

I'm thinking you should begin with scrolling disabled for scrollview and user interaction enabled for both. Then in touchesBegan: you should check for number of touch points. If it's only one (aka user wants to draw) you do nothing (disabling interaction for scrollview would disable it for all subviews as well). However, if the number of touch points is greater than one, enable scrolling then do

[UIView setUserInteractionEnabled: NO]

This way, no lines should be drawn on the UIView when you pinch or zoom with two fingers on the UIScrollView.



回答3:

I helped developed an app that required a signature plate with in a scroll view, and a scroll view's subviews are weird to touch events, sometimes you have to hold your finger there for it to pass through the scroll view and reach the inner views, so there was a bit of a lag... but what i ended up doing was subclassing a UIScrollView and overriding the

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {}

method and if the touch landed with in the frame of the signature plate it would [scrollView setScrollEnabled:NO]; and the drawing happened sooner and more smoother... the only problem is they couldn't scroll the scroll view from that box.. basically i created a dead spot with in the scroll view

but, that's a little wonky, i think a UITableView might work better for you... just make it 1 giant table cell, i think you will get better results....



回答4:

Don't forget to enable 'Multiple Touch' for these features.