I have a UIView (lets call it myView), inside a UIScroller.
myView has elements that can be dragged on it.
When one of these elements are touched, the scroller is locked, to prevent the whole thing from scrolling. The elements have exclusiveTouch = YES. I need the whole thing to scroll when just myView is touched.
I had this working with touchesBegan, touchesMoved, etc., but I am converting this class to gestures. The new class has two gestures attached to it: UIPanGestureRecognizer and UITapGestureRecognizer. Something like:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(drag:)];
[panGesture setMaximumNumberOfTouches:1];
[panGesture setDelegate:self];
[myView addGestureRecognizer:panGesture];
[panGesture release];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(tapAdd:)];
[singleTap setDelegate:self];
[singleTap setNumberOfTapsRequired:1];
[myView addGestureRecognizer:singleTap];
[singleTap release];
When this class used the old methods (touchesBegan, etc.), I simply forwarded the touches using something like
[self.nextResponder touchesBegan: touches withEvent:event];
but how do I do that using gestures? I mean, the UIPanGestureRecognizer will, in my case, run a method called drag: and this method receives a gesture… how do I forward the touch to its scroller parent, so the whole thing scrolls?
thanks
It’s possible you could set up a protocal to make a delegate of your view.
In your header, set up
You’ll have to synthesize
delegatein the implementation file.In the scroller class, you will have to use the protocol
In that implementation file, make sure to put
myView.delegate = self;when initializing it and add- (void)drag {and do what you want in there. If you need more info, you can of course assing the method in your protocol to be something like- (void)dragWithEvent:(UIEvent *)eventor something similar.Then when you call
drag:in myView, you can forward this to the protocol method by calling[self.delegate dragWithEvent:event];.I realize this is a bit extensive to get your scroller to scroll, but it will forward the message like you want.
It’s also possible that you could add the gestures to the scroller rather than to myView, then forward all touches in the
touchesBeganmethod and let the scroller handle it directly