Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 833001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:26:58+00:00 2026-05-15T04:26:58+00:00

I am loading in images with varying sizes and putting them in UIScrollViews, all

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:26:58+00:00Added an answer on May 15, 2026 at 4:26 am

    Edit: previous version was sizing the image to the view rather than the other way around. I think this should correct that:

    double imgRatio = imageSize.width / imageSize.height;
    double viewRatio = viewSize.width / viewSize.height;
    
    if ( imgRatio >= viewRatio )
    {
        initialPos.size.width = imageSize.width;
        initialPos.size.height = imageSize.width / viewRatio;
        initialPos.origin.x = 0;
        initialPos.origin.y = (imageSize.height - initialPos.size.height) / 2;
    }
    else
    {
        initialPos.size.height = imageSize.height;
        initialPos.size.width = imageSize.height * viewRatio;
        initialPos.origin.y = 0;
        initialPos.origin.x = (imageSize.width - initialPos.size.width) / 2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fire an event after loading all images. And also, I want
I have images on my page. User can add more images onto the page
I have tried many ways of Asynchronously loading images and they ALL have this
I am loading images from a database and want to dynamically resize them according
I'm loading images with this class. I need help on how to stop them
i'm loading images into a UIView inside a UIscrollview using performSelectorInBackground to fetch the
With all the smarts of actually loading images being done by the .net framework,
I'm lazy loading images from the web and tossing them into UIImageViews that I
Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte
Having some annoying issues with loading images into a BufferedImage (image in the example)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.