PDA

View Full Version : UIScrollView Question




atmenterprises
Feb 15, 2009, 08:15 PM
I'll do my best to explain this and hope someone understands. I've searched the Apple developer's forum as well as anything I could find on Google for the last four hours with nothing.

My application has a UIScrollView that houses a UIImageView. I can pinch and zoom in as well as pinch and zoom out. All of those things work perfectly. However, I do have one issue: let's say I zoom in and slide over to a corner or side of the UIImageView. Then I put my fingers down and zoom out. The image obviously gets smaller, but shrinks from all sides (again, obviously) and I end up seeing a gap between the edge of the image and the edge of the screen until I let my fingers go, then it slides back into the 0,0 (x,y) position, which is the top left corner.

I set a background color on the UIScrollView to see what caused that gap and it is, indeed, the UIScrollView. So when zooming out (making the image smaller), the UIScrollView doesn't keep the edge of the image up against the edge of the UIScrollView. Instead, it allows the image to scale down beyond the bounds of the UIScrollView, then just moves the image back into place. But to be more specific, I have the minimum scroll set to 1.0, so the image never gets any smaller than that (and at that minimum, the imageview fills the entire UIScrollView nicely). It's just that the side of the image closest to my fingers isn't "sticky" to the edge of the UIScrollView, and thus a gap is created upon zooming out, albeit temporarily, until I pull my fingers off the screen.

My App Delegate Implementation (AppDelegate.m):


#import "Bump_AppDelegate.h"
#import "GameViewController.h"

@implementation Bump_AppDelegate

@synthesize window, viewController, gameBoardScrollView, board;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// load the view controller from the HelloView nib file
GameViewController *vController = [[GameViewController alloc]
initWithNibName:@"GameViewController" bundle:[NSBundle mainBundle]];

// Create a temporary image for the UIScrollView
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_to_zoom.png"]];

[self setBoard:tempImageView];

[tempImageView release];

gameBoardScrollView.maximumZoomScale = 2.5;
gameBoardScrollView.minimumZoomScale = 1.0;
gameBoardScrollView.clipsToBounds = YES;
gameBoardScrollView.alwaysBounceVertical = NO;
gameBoardScrollView.alwaysBounceHorizontal = NO;
gameBoardScrollView.bounces = NO;
gameBoardScrollView.bouncesZoom = NO;
gameBoardScrollView.showsVerticalScrollIndicator = NO;
gameBoardScrollView.showsHorizontalScrollIndicator = NO;
gameBoardScrollView.pagingEnabled = NO;
gameBoardScrollView.delegate = self;

// set the view
self.viewController = vController;

// release the view controller
[vController release];

// Override point for customization after application launch
[window addSubview:[viewController view]];
[gameBoardScrollView addSubview:board];
[window addSubview:gameBoardScrollView];
[window makeKeyAndVisible];
}

And my App Delegate Header (AppDelegate.h):

#import <UIKit/UIKit.h>
#import "GameViewController.h"

@class GameViewController;

@interface Bump_AppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate> {
IBOutlet UIWindow *window;
IBOutlet GameViewController *viewController;
IBOutlet UIScrollView *gameBoardScrollView;

// Game board
UIImageView *board;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) GameViewController *viewController;
@property (nonatomic, retain) UIScrollView *gameBoardScrollView;
@property (nonatomic, retain) UIImageView *board;
@end

Help???



dejo
Feb 15, 2009, 09:14 PM
Help???
Is your question: can you, and if so how, eliminate the gap?

atmenterprises
Feb 15, 2009, 09:18 PM
Is your question: can you, and if so how, eliminate the gap?

Yes!

dejo
Feb 16, 2009, 11:55 AM
Have you tried playing with the bounce settings of the UIScrollView?

atmenterprises
Feb 16, 2009, 03:08 PM
I've turned bounces, alwaysBouncesVertical, alwaysBouncesHorizontal and bouncesZoom to all YES with the same result. Thanks for the suggestion, though.

dejo
Feb 16, 2009, 10:11 PM
I've turned bounces, alwaysBouncesVertical, alwaysBouncesHorizontal and bouncesZoom to all YES with the same result. Thanks for the suggestion, though.
Now try setting them to NO, or at least 'bouncesZoom'. I'll leave it to you to read up on the bouncesZoom property of the UIScrollView to learn why that should be the case.

atmenterprises
Feb 17, 2009, 05:25 AM
Now try setting them to NO, or at least 'bouncesZoom'. I'll leave it to you to read up on the bouncesZoom property of the UIScrollView to learn why that should be the case.

Yeah, they're all set to NO in the original code, so I've tried that already with no luck.

I did discover something interesting: the photos application does exactly the same thing, so this might be an inherent action of the UIScrollView. I'm not sure how to code around it at this point, but it may just be something I have to deal with.