4

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.

4 Answers 4

4
+100

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

myScrollView.panGestureRecognizer.minimumNumberOfTouchesRequired = 2;
Sign up to request clarification or add additional context in comments.

6 Comments

this looks cool, it will be the first thing I will try. Problem is that currently I don't have enough time to do this.
This usually works for most of the cases, have used it quite a few times. But pre iOS 5, I had gone the route of subclassing UIScrollView and overriding the touchesShould* methods
Irony: putting a bounty on a question and then informing people who post answers that you don't have time to implement their suggestions.
Life happens. You can't expect someone to be able to try something immediately when it took nearly a month to get more than one answer.
Bounty ends in couple hours it would be a pity to waist it, so here you go without testing your solution.
|
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.

4 Comments

will it work? Two touches will not come simultaneously so I can't just disable user interaction for scroll view, at least not immediately.
It should work, when two touches are present, you should disable interaction on the UIView you want to draw on (not scrollView) because two touches means you want to pan or zoom in/out. If there's only one touch point then obviously the user wants to draw but even the other finger is a little delayed, it should still work. As soon as the second finger touches your code will notice it and do zoom in/out instad of draw instead.
@MarekR Any progress on this particular problem?
sorry, but curently I have a headache with other issues and simply I don't have a time to try it (some release was speed up). Anyway Steven McGraths approach looks much more promising.
1

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....

2 Comments

What you can do is open your XIB / Storyboard. Click on your table view / scroll view, and deselect Delays Content Touches. this makes it more responsive.
Yes, but my idea is to disable scrolling when single finger is used (this should go immediately to children) and scroll/zoom when two fingers are used. I do not have spatial places in content like you.
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.