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 4559850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:50:50+00:00 2026-05-21T17:50:50+00:00

I have an UIImageView inside an UIScrollView. I want that the user can zoom

  • 0

I have an UIImageView inside an UIScrollView. I want that the user can zoom and navigate the image.

This is my work code:

//img is the UIImageView
//scroller is the UIScrollView

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return img; 
}
- (void)viewDidLoad {
   [super viewDidLoad];
   UIImage *image = [UIImage imageNamed:@"map_screen.png"];
   img = [[UIImageView alloc] initWithImage:image];
   scroller.delegate = self;
   scroller.autoresizesSubviews = YES;
   scroller.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
   scroller.contentSize = img.frame.size;
   scroller.scrollEnabled = YES;
   scroller.directionalLockEnabled = NO;
   scroller.userInteractionEnabled = YES;

   CGSize ivsize = img.frame.size;
   CGSize ssize = scroller.frame.size;

   float scalex = ssize.width / ivsize.width;
   float scaley = ssize.height / ivsize.height;
   scroller.minimumZoomScale = fmin(1.0, fmax(scaley, scalex));
   scroller.zoomScale = fmin(1.0, fmax(scalex, scaley));
   [scroller addSubview:img];
   img.userInteractionEnabled = YES;
}

all works, but this happened: the minimum zoom is the height of the screen.
My image has the width bigger than the height, so i want that the minumum zoom is the width.

If i write

scroller.minimumZoomScale = fmin(1.0, scalex);

works, but when the user zooms out, the image is not at the center of the screen, but at the top.

i’ve tried something like this

CGPoint scrollCenter = [scroller center];
[img setCenter:CGPointMake(scrollCenter.x, scrollCenter.y)];

or

img.center = scroller.center;

but with this solution, the image is not completly scrollable, and if i zoom out, it stay again at the top of the screen, but is not completly visible!

What can i do for fix it?

  • 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-21T17:50:51+00:00Added an answer on May 21, 2026 at 5:50 pm

    You have to do it manually while the zooming is in progress using the scrollViewDidZoom delegate function… something like

    - (void)scrollViewDidZoom:(UIScrollView *)scrollView
    {
    
        // center the image as it becomes smaller than the size of the screen
        CGSize boundsSize = scrollView.bounds.size;
        CGRect frameToCenter = imageView.frame;
    
        // center horizontally
        if (frameToCenter.size.width < boundsSize.width)
        {
            frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
        } else {
            frameToCenter.origin.x = 0;
        }
    
        // center vertically
        if (frameToCenter.size.height < boundsSize.height) 
        {
            frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
        } else {
            frameToCenter.origin.y = 0;
        }
    
        imageView.frame = frameToCenter;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIImageView that is housed inside a UIScrollView . The image in
in my app i have UIImageView inside UIScrollview which i can zoom in and
I have a uiscrollview and there is a uiimageview inside it. I want the
I have a UIImageView inside of my UIViewController. It loads an image that is
I have a UIImageView that I allocated inside of a UIView. I want to
I have an UIImageView with an image (map) inside of a UIScrollView. I add
I have an image inside an UIImageView which is within a UIScrollView. What I
I Have a UIScrollview with a UIImageView inside where I scroll from an image
I have a UIScrollView and inside it there is a UIImageView with an image.
I have a subview in my app that contains a UIImageView. The user can

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.