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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:41:33+00:00 2026-06-01T14:41:33+00:00

I have a uiscrollview and there is a uiimageview inside it. I want the

  • 0

I have a uiscrollview and there is a uiimageview inside it. I want the used to be able to zoom in out of the image since it’s a big image. the scrollview only needs to scroll vertically not horizontally.

before adding the zooming effect I had the following code and it worked as I wanted,

-(void)viewDidLoad
{
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 1690)];
}

So I did some research and ended up with the following code to enable pinch zoom in and out,

-(void)viewDidLoad
{
scrollView.scrollEnabled = YES;

[scrollView setContentSize:CGSizeMake(320, 1690)];
scrollView.delegate = self;
//    scrollView.contentSize = instImage.frame.size;
scrollView.minimumZoomScale = scrollView.frame.size.width / instImage.frame.size.width;
scrollView.maximumZoomScale = 2.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
[[NSRunLoop currentRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate distantFuture]];

 }


 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

return instImage;
}


 - (CGRect)centeredFrameForScrollView:(UIScrollView *)scroll andUIView:(UIView *)rView {

CGSize boundsSize = scroll.bounds.size;
CGRect frameToCenter = rView.frame;

// center horizontally
if (frameToCenter.size.width < boundsSize.width) {

    frameToCenter.origin.x = ((boundsSize.width - frameToCenter.size.width) / 2);

}else {

    frameToCenter.origin.x = 0;
 }

return frameToCenter;
 }


 - (void)scrollViewDidZoom:(UIScrollView *)scrollV {

instImage.frame = [self centeredFrameForScrollView:scrollV andUIView:instImage];;
 }

Now I have the following problems and I can’t figure out what’s wrong,

  1. when the view is just loaded before any pinch the scrollview doesn’t scroll all the way to the end of the image.

  2. when pinched to zoom in, it scrolls left and right and up and down the image, but still it doesn’t scroll down all the way to the end of the image, but still more than what it originally did at the begining.

  3. when I zoom out, the whole thing stops. you can’t zoom in or out, it doesn’t even scroll anymore. totally locked.

I did some reseach and found the following post.
https://stackoverflow.com/a/6384834/1103257

but I don’t know where would I find NSDefaultRunLoopMode or even how to search for it to figure out whether this can solve it or not.

  • 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-06-01T14:41:34+00:00Added an answer on June 1, 2026 at 2:41 pm

    I finally got it. This solution works perfectly!

    in your .h file

    @interface scrollViewController : UIViewController <UIScrollViewDelegate>{
    
          float oldScale;
    
          IBOutlet UIScrollView *scrollView;
          IBOutlet UIImageView  *image;
    }
    
    @end
    

    and just connect the image to the uiimageview that has the photo that you want to zoom in and out and is inside your scrollview. then connect the scrollview to your uiscrollview on your interface.

    in your .m file

    @implementation scrollViewController
    
    
    -(void)viewDidLoad
    {
    [super viewDidLoad];
    
    scrollView.scrollEnabled = YES;
    scrollView.minimumZoomScale=1.0;
    scrollView.maximumZoomScale=4.0;
    [scrollView setContentSize:CGSizeMake(320, 1700)];
    scrollView.delegate=self;
    
     }
    
     - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
     {
         return image;
     }
    
     - (void)scrollViewDidEndZooming:(UIScrollView *)scrollV withView:(UIView *)view atScale:(float)scale
     {
         [scrollView setContentSize:CGSizeMake(scale*320, scale*1700)];
     }
    
      @end
    

    hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIScrollView and inside it there is a UIImageView with an image.
in my app i have UIImageView inside UIScrollview which i can zoom in and
I have a UIScrollView with a UIView inside. I want to lock the x-axis
I have a UIImageView inside of a UIScrollView. The parent scroll view allows zooming
I have a UIScrollview with paging enabled. There are 3 views (pages) inside this
I have a UIScrollView loaded with a UIImageView, so that the user can zoom
I have a pretty big uiscrollview (1700p) which contains a uiimageview as the background,
I have been trying to implement pinch zoom/in-out for PhotoView (a UIImageView instance) using
I have a UIImageView (initialized with Aspect Fill) inside a UIScrollView. The user shall
I have a UIScrollView that contains an image and a segmented control that allows

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.