1

I have a custom pinch gesture recognizer that I am replacing UIScrollView's pinch gesture recognizer with. Let's assume I want this pinch gesture recognizer to behave exactly 100% like UIScrollView's pinch gesture recognizer. Could I set the gesture recognizer's selector somehow to effect this?

Like perhaps

GPinchGestureRecognizer *graphPinch = [[GPinchGestureRecognizer alloc] initWithTarget:scrollView action:@selector(pinchHandler:)];

Or something?

In reality I do want the recognizer to behave almost exactly like the one that comes with UIScrollView, except that in the views contained within the UIScrollView I override setTransform and I want to restrict transform alteration based on flags set in this custom pinch recognizer. Trying to reverse/guess-engineer everything higher up the call stack that UIScrollView's pinch gesture recognizer does has proven hard and annoying. I need my custom recognizer to do some arithmetic with the touches that sets some flags that are read in setTransform, but besides that I want completely standard UIScrollView pinch behavior.

Randall Schmidt
  • 93
  • 1
  • 12

1 Answers1

1

Why not just use the property that the scroll view has for a pinch gesture recognizer.

Something like.

myScrollView.pinchGestureRecognizer = graphPinch;

EDIT: whoops, nevermind, that is read-only.

Instead, use that pinchGestureRecognizer to override the behavior you want. You can also use the other properties of the UIScrollView to catch when it is scrolling.

Methods are listed here:

UIScrollView

UIPinchGestureRecognizer

Justin Paulson
  • 4,388
  • 1
  • 23
  • 28
  • Yeah I noticed that right after I submitted, you can use it though to see what kind of scaling it is performing and do your arithmetic – Justin Paulson Jul 03 '12 at 16:01
  • What I really need is to see what methods the standard recognizer is calling. I've been trying to imitate it for a while but not having much luck. – Randall Schmidt Jul 03 '12 at 16:30
  • 1
    You can become it's delegate and catch these http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intf/UIScrollViewDelegate mainly these ones `scrollViewWillBeginZooming:withView:` `scrollViewDidEndZooming:withView:atScale:` `scrollViewDidZoom:` – Justin Paulson Jul 03 '12 at 16:52
  • I could but that wouldn't tell me anything about what methods the pinch gesture calls to operate on the view to scale it. I can't just set a new affinetransform and change the content size because I have some complicated things going on that work with the standard recognizer but not with my custom one. The standard one (or rather, the UIScrollView superclass, at its behest) is calling methods and doing operations and I need to know what those are. – Randall Schmidt Jul 03 '12 at 18:18
  • Well from the documentation I've given you, that is everything you get with UIScrollView. You can see when it starts zooming, what the zoom scale is, what the offset of the origin is, If it is zooming, if it is bouncing, the velocity and scale of the pinch gesture, The location of the touches, the number of touches, maybe if you give more detail as to what you are trying to do I could narrow this down a bit, but there is plenty of information available from the documentation I linked. Are you just trying to keep some views from resizing? – Justin Paulson Jul 03 '12 at 18:35
  • In response to a pinch gesture a UIScrollView by default does a number of operations. These include changing its views affine transforms, changing its content size, etc. I need to either know what these under-the-hood operations are, or replace the UIScrollView's pinch gesture recognizer with my own, and have it call the same selector as the default recognizer. If I could view the implementation of the method that the default pinch recognizer calls when the touches move, that would 100% answer my question. But that is not public. – Randall Schmidt Jul 03 '12 at 19:27
  • The `UIPinchGestureRecognizer` on `UIScrollView` also has a delegate that you can set, plus all the usual interrogative methods available on `UIGestureRecognizer`, full stop. They might be of some use. – Dafydd Williams Aug 31 '12 at 06:57