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

  • Home
  • SEARCH
  • 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 6865023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:59:17+00:00 2026-05-27T02:59:17+00:00

I have one view controller in which I have added UIScrollView & UIImageView programatically.

  • 0

I have one view controller in which I have added UIScrollView & UIImageView programatically. I have added UIPichGestureRecognizer to the UIImageView. My UIImageView is added to UIScrollView as a subview.

My problem is when I try to pinch the image , it zoom in. But when I release the touches from screen it again come to its default size. I can not find the error in code. Please help me.
Below is my code

 - (void)createUserInterface {

    scrollViewForImage = [[UIScrollView alloc]initWithFrame:CGRectMake(20.0f, 60.0f, 280.0f, 200.0f)];
    scrollViewForImage.userInteractionEnabled = YES;
    scrollViewForImage.multipleTouchEnabled = YES;
    scrollViewForImage.backgroundColor = [UIColor redColor];
    scrollViewForImage.autoresizesSubviews = YES;
    scrollViewForImage.maximumZoomScale = 1;
    scrollViewForImage.minimumZoomScale = .50;
    scrollViewForImage.clipsToBounds = YES;
    scrollViewForImage.delegate = self;
    scrollViewForImage.bouncesZoom = YES;
    scrollViewForImage.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:scrollViewForImage];

    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 200.0f)];
    [imageView setBackgroundColor:[UIColor clearColor]];
    imageView.userInteractionEnabled = YES;
    imageView.multipleTouchEnabled = YES;

    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
        [pinchRecognizer setDelegate:self];
        [imageView addGestureRecognizer:pinchRecognizer];
    //[self.contentView addSubview:imageView];
    [self.scrollViewForImage addSubview:imageView];

    scrollViewForImage.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);

}


-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
    return imageView;
}

-(void)pinch:(id)sender {

    [self.view bringSubviewToFront:[(UIPinchGestureRecognizer*)sender view]];

    if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

        lastScale = 1.0;
        return;
    }

    CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
    CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
    [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
    lastScale = [(UIPinchGestureRecognizer*)sender scale];
}
  • 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-27T02:59:18+00:00Added an answer on May 27, 2026 at 2:59 am

    From what I can see the problem lies here:

    scrollViewForImage.maximumZoomScale = 1;
    

    You are setting the maximum zoom scale of the image to 1 x its full size. This means once you finish pinching the image, it will scale back to 1 x its size.

    If you want to be able to zoom the image to a larger size, try settings this value to be higher than 1. e.g.

    scrollViewForImage.maximumZoomScale = 3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my view of my iPhone app, I have added one sub view, which
I have an integer variable ( time ) in one view controller whose value
I have the CakePHP stack in /var/www/site from one view under controller A I
When submitting one form from view, how can i also read or have controller
I have senario in which one view and view has binding with multiple ViewModel.
I have a navigation view controller which navigates between some tableviews and I've just
I have a simple Rails 3 app: no models, one view and one controller
I've one more question. I have a view which is containing an add link.
I have added the Authentication attribute on controller classes which are for admin purposes
I have a UIImagePickerController as one view in a TabBar setup. Is it possible

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.