I did something like what you describe once. I remember to take it off, I created a new UIGestureRecgonizer , which I called UIDownwardDragGestureRecognizer . I think I then repeated through the scrollviews of gesture recognizers so that they wait for the UIDownwardGestureRecognizer fail, for example:
UIDownwardDragGestureRecognizer *downwardGesture = [UIDownwardGestureRecognizer alloc] initWithTarget:self action:@selector(downwardGestureChanged:)]; [myScrollview addGestureRecognizer:downwardGesture]; for (UIGestureRecognizer *gestureRecognizer in myScrollview.gestureRecognizers) { [gestureRecognizer requireGestureRecognizerToFail:myDownwardGesture]; }
Once you have this setting, you can do something like :
- (void) downwardGestureChanged:(UIDownwardDragGestureRecognizer*)gesture { CGPoint point = [gesture locationInView:myScrollView]; if (gesture.state == UIGestureRecognizerStateBegan) { UIView *draggedView = [myScrollView hitTest:point withEvent:nil]; if ([draggedView isTypeOfClass:[UIImageView class]]) { self.imageBeingDragged = (UIImageView*)draggedView; } } else if (gesture.state == UIGestureRecognizerStateChanged) { self.imageBeingDragged.center = point; } else if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled || gesture.state == UIGestureRecognizerStateFailed) {
In UIGestureRecognizerStateBegan, as soon as you find the UIImageView, you can remove it from the supervisor (scrollview) and add it as a spy to some other container. If you do this, you will need to translate the point into the new coordinate space. If you want the original image to remain in scrollview, make a copy of it and add it to the external container.
In order to try out the above example and see how it works, you may need to disable cropping on scrollview, as the above example drags the UIImageView out of the scroll (although you usually add it to some containing view).
source share