Formula for producing a CGRect for a UIScrollView, that displays a UIImage in scaled to fit way
Posted
by RickiG
on Stack Overflow
See other posts from Stack Overflow
or by RickiG
Published on 2010-06-03T11:49:51Z
Indexed on
2010/06/03
15:54 UTC
Read the original article
Hit count: 287
Hi
I am loading in images with varying sizes and putting them in UIScrollViews, all the images are larger than the UIScrollView. The user can scroll and zoom as they please, but initially I would like for the image to be centered and scaled so the largest side of the image aligns with the edge of the scrollView, i.e. if the picture is in landscape I would like to size and scale it so that the left and right side goes all the way to the edge of the UIScrollVIew and vice versa
I found a formula in a utility function in the Programming guide but it does not quite fit my needs.
My approach is to use:
CGrect initialPos = ?
[self.scrollView zoomToRect:initialPos animated:YES];
I know the size of my scrollView and the size of my image, what I need to figure out is the scale and CGRect to apply to the scrollView to center and size my image.
Hope someone can help out:) Thanks
© Stack Overflow or respective owner