Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 17, 2009, 08:11 AM   #1
ghanalupo
macrumors newbie
 
Join Date: Sep 2009
centred image scalled in scrollview

I have managed to get an image to scale correctly into a scrollview so that no matter how wide the image is it initially displays scaled down so the width is 320 and the image fits nicely in the view.

The problem is the height is not centred so the image although sitting nicely scaled width wise gets pushed up at origin 0,0 of the scrollview.

I have been trying to figure out how to get the image to initially display scaled so you can see the entire image scaled nicely and centred on the screen.

I have had some success, but in doing so has created further confusion and problems!

I can get the image no matter what the size to sit centred scaled enough to see the entire image like this:

Code:
minimumScale = [scrollingView frame].size.width  / [contentView frame].size.width;
    
float heightScale = [scrollingView frame].size.height  / [contentView frame].size.height;
    
contentHeightOffset = -(heightScale * [scrollingView frame].size.height / 2);
	
[scrollingView setMinimumZoomScale: minimumScale];
    
[scrollingView setZoomScale: minimumScale];
		
scrollingView.contentOffset =  CGPointMake(0, contentHeightOffset); 
	
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
	
if (scale == minimumScale) scrollingView.contentOffset =  CGPointMake(0, contentHeightOffset);
This works, but I do not understand that in order for it to do so I have to use the negative of (heightScale * [scrollingView frame].size.height / 2);

That puzzles me!

But it works?

Then I have the added problem that when the view stops scrolling it tries to reset itself to origin 0,0 when it gets sufficiently small enough. So I put code in to test if it hase reached minimum zoom which works....but then you see it bounce back from origin 0,0 to the desired start place?


Any tips will glady save my sanity!

Thanks
ghanalupo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help needed with Uitableview in scrollview deadsoldier10 iPhone/iPad Programming 0 Oct 13, 2011 01:46 AM
zooming animation problem in ScrollView - Ipad ashwinr87 iPhone/iPad Programming 0 Apr 14, 2011 03:05 PM
Scrollview with Multiple images like in ebay home view? AbhishekApple iPhone/iPad Programming 1 Sep 14, 2010 08:06 AM
Touch in scrollview Binju iPhone/iPad Programming 4 Mar 15, 2010 10:54 AM
Display images as loop in scrollview Binju iPhone/iPad Programming 0 Mar 15, 2010 02:29 AM


All times are GMT -5. The time now is 01:18 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC