Take the 2-minute tour ×

I have a UIImageView contained within a UIScrollView. The image is (usually) big, so the user can zoom it out in order to see the whole thing.

Upon zooming out, though, UIScrollView snaps the ImageView to the top-left of the scrollview. I want this to be positionable by the user, and haven't found a way to "turn it off" yet.

It's kinda like always allowing scrolling, rather then only allowing scrolling when the image is zoomed in. Maybe it's too major of a change?

Anyone know of a way? Originally, I was just going to create this functionality manually. But UIImageViews don't like to adjust to new sizes (I've tried about everything and can't get UIImageView to resize UNLESS I remove the picture from the imageView, change the frame, and re-add it).

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I ended up disabling the UIScrollView's panGestureRecognizer and subbing in a custom one.

Here's a quick snippet on how to disable it:

// Disable our GestureRecognizer
for (UIGestureRecognizer *gesture in scrollView.gestureRecognizers){
    if ([[NSString stringWithFormat:@"%@",[gesture class]] isEqualToString:@"UIScrollViewPanGestureRecognizer"]){
        [gesture setEnabled:NO];

A bit of a hack-job there, but it's due to the fact that UIScrollViews have changed the class of the GestureRecognizer to "UIScrollViewPanGestureRecognizer." The compiler will yell at you if you try to use that class (there's probably a better solution out there).

share|improve this answer
if ([gestureRecogniser isMemberOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")]) –  Alec May 24 '12 at 23:19
if ([gestureRecogniser isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")]) –  nacho4d Jun 8 '12 at 4:02
There is a panGestureRecognizer property on UIScrollView as of iOS 5 that avoids this hack. developer.apple.com/library/ios/documentation/UIKit/Reference/… –  Robert Nov 7 '13 at 15:32
Any hints on the custom method you subbed in after disabling the gesture recognizer? I have no problems centering the image after zooming out. But I don't want to center it. I want to let the user position the image whether it's zoomed in or zoomed out. Any help appreciated. –  crgt Nov 30 '13 at 4:40

If you locate the UIImageView at location 0,0 in the UIScrollView, then that's always going to be the upper-left. If you want it to be centered in the scrollview when it's smaller than the view, you need to position it there. Check whether its -size is bigger or smaller than the scrollview's. If it's smaller than the scrollview, set its -center to be the same as the scrollview's.

share|improve this answer
This works perfectly for keeping the UIImageView at the center of the scrollView, but I was wondering if you knew a way to keep the UIImageView at the position it's dragged to, rather then snapping back to the center? –  Chewmieser Mar 15 '11 at 20:50

Your Answer


