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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:21:08+00:00 2026-06-13T04:21:08+00:00

This question is a follow-up from another SO question from a while back: zooming

  • 0

This question is a follow-up from another SO question from a while back: zooming using pinch but not using transform methods. I got the zooming to work pretty near perfectly, however it will still make the drawn image ‘jump around’ as I’ve been calling it. The most important parts of the code are the following:

When a pinch event is observed this method is called:

[code snippet 1]

- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
    float previousZoomLevel = zoomLevel;
    UIPinchGestureRecognizer *pinch = (UIPinchGestureRecognizer *)sender;

    float zoomIncreaseFactor = [self getZoomFactor:[pinch scale]]; //= 13 or 7 or 10
    float estimatedDelta = (previousZoomLevel * zoomIncreaseFactor) / 150;

    if ([pinch scale] > previousScale) {
        zoomLevel += estimatedDelta;
    }

    if ([pinch scale] < previousScale) {
        zoomLevel -= estimatedDelta;
    }

    previousScale = [pinch scale];

    if (zoomLevel < MIN_ZOOM_LEVEL) {
        zoomLevel = MIN_ZOOM_LEVEL;
    }

    if (zoomLevel > MAX_ZOOM_LEVEL) {
        zoomLevel = MAX_ZOOM_LEVEL;
    }

    CGPoint loc = [pinch locationInView:self];

    NSLog(@"loc: {%.1f,%.1f}, lastPinchLoc: {%.1f,%.1f}", loc.x,loc.y,lastPinchLocation.x,lastPinchLocation.y);

    //uncomment the below part to always zoom from the first zoom location.
    //if (lastPinchLocation.x != 0 && lastPinchLocation.y != 0) {
        //loc.x += lastPinchLocation.x - loc.x;
        //loc.y += lastPinchLocation.y - loc.y;
    //}

    //NSLog(@"newLastPinchLocation: {%.1f,%.1f}", loc.x,loc.y);

    lastPinchLocation = loc;

    hasBeenMoved = YES;

    if (zoomLevel != previousZoomLevel) {
        [self setNeedsDisplay];
    }
}

The above NSLog gives the following prints when i pinch all over the screen:

2012-10-16 10:15:19.357 App[2609:907] loc: {147.0,232.0}, lastPinchLoc: {0.0,0.0}
2012-10-16 10:15:19.391 App[2609:907] loc: {147.0,231.0}, lastPinchLoc: {147.0,232.0}
2012-10-16 10:15:19.436 App[2609:907] loc: {148.0,232.0}, lastPinchLoc: {147.0,231.0}
2012-10-16 10:15:19.457 App[2609:907] loc: {148.0,232.0}, lastPinchLoc: {148.0,232.0}
2012-10-16 10:15:19.474 App[2609:907] loc: {148.0,233.0}, lastPinchLoc: {148.0,232.0}
2012-10-16 10:15:19.507 App[2609:907] loc: {147.0,233.0}, lastPinchLoc: {148.0,233.0}
2012-10-16 10:15:19.573 App[2609:907] loc: {103.0,355.0}, lastPinchLoc: {147.0,233.0}
2012-10-16 10:15:20.324 App[2609:907] loc: {585.0,710.0}, lastPinchLoc: {103.0,355.0}
2012-10-16 10:15:20.340 App[2609:907] loc: {584.0,709.0}, lastPinchLoc: {585.0,710.0}
2012-10-16 10:15:20.356 App[2609:907] loc: {584.0,710.0}, lastPinchLoc: {584.0,709.0}
2012-10-16 10:15:20.374 App[2609:907] loc: {584.0,710.0}, lastPinchLoc: {584.0,710.0}
2012-10-16 10:15:20.407 App[2609:907] loc: {583.0,710.0}, lastPinchLoc: {584.0,710.0}
2012-10-16 10:15:20.456 App[2609:907] loc: {512.0,811.0}, lastPinchLoc: {583.0,710.0}
2012-10-16 10:15:21.056 App[2609:907] loc: {645.0,163.0}, lastPinchLoc: {512.0,811.0}
2012-10-16 10:15:21.090 App[2609:907] loc: {647.0,164.0}, lastPinchLoc: {645.0,163.0}
2012-10-16 10:15:21.107 App[2609:907] loc: {647.0,165.0}, lastPinchLoc: {647.0,164.0}
2012-10-16 10:15:21.156 App[2609:907] loc: {602.0,249.0}, lastPinchLoc: {647.0,165.0}
2012-10-16 10:15:21.839 App[2609:907] loc: {153.0,702.0}, lastPinchLoc: {602.0,249.0}
2012-10-16 10:15:21.856 App[2609:907] loc: {157.0,703.0}, lastPinchLoc: {153.0,702.0}
2012-10-16 10:15:21.874 App[2609:907] loc: {159.0,704.0}, lastPinchLoc: {157.0,703.0}
2012-10-16 10:15:21.890 App[2609:907] loc: {160.0,704.0}, lastPinchLoc: {159.0,704.0}
2012-10-16 10:15:21.906 App[2609:907] loc: {123.0,796.0}, lastPinchLoc: {160.0,704.0}
2012-10-16 10:15:21.923 App[2609:907] loc: {125.0,794.0}, lastPinchLoc: {123.0,796.0}
2012-10-16 10:15:22.706 App[2609:907] loc: {368.0,303.0}, lastPinchLoc: {125.0,794.0}
2012-10-16 10:15:22.723 App[2609:907] loc: {369.0,307.0}, lastPinchLoc: {368.0,303.0}
2012-10-16 10:15:22.725 App[2609:907] loc: {369.0,307.0}, lastPinchLoc: {369.0,307.0}
2012-10-16 10:15:22.739 App[2609:907] loc: {371.0,312.0}, lastPinchLoc: {369.0,307.0}
2012-10-16 10:15:22.756 App[2609:907] loc: {374.0,312.0}, lastPinchLoc: {371.0,312.0}
2012-10-16 10:15:22.773 App[2609:907] loc: {338.0,392.0}, lastPinchLoc: {374.0,312.0}

Just before drawing an item on the CGContext the x and y are put into this method and i draw the item on the returned location. The class variable ‘zoomTouchLocation’ has the same value as ‘lastPinchLocation’ in the above snippet.

[code snippet 2]

- (CGPoint)handleCoordinatesX:(float)x y:(float)y {
    x -= zoomTouchLocation.x;
    y -= zoomTouchLocation.y;

    x = x * zoomLevel;
    y = y * zoomLevel;

    x += zoomTouchLocation.x;
    y += zoomTouchLocation.y;

    return CGPointMake(x, y);
}

If i pinch in roughly the same location each time it will work as intended, but when i pinch all over the screen the image jumps around like crazy.

Now basically my question is if anyone can help me with this ‘jumping around’ problem and get the image to scale from the location i zoomed at without jumping around. If you need any more information just ask in the comments below.

(and i do know it’s quite normal that the jumping occurs with my code as it is, i just can’t find the way to stop it from doing that)

  • 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-13T04:21:09+00:00Added an answer on June 13, 2026 at 4:21 am

    It’s hard to help without the whole code but you should try to set the view.layer.anchorPoint to your pinchLocation (if it’s not already done).
    Like this, when the transformation is done, this point doesn’t move. Really useful for rotation or scaling.

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

Sidebar

Related Questions

This is a follow-up to another question I asked: Android -- get MEID from
This is a follow on from another question ( https://stackoverflow.com/questions/10712659/c-class-design-for-monte-carlol-simulation ) I am planning
This question is a follow on from this one ... I am binding to
This is a follow-on from this question, in which I was trying to suppress
This is a follow on from my previous question although this is about something
This is a follow up question from Calling constructor in return statement . This
This is a follow-on question from the one I asked here . Can constraints
This is a follow up from my previous question I have this code basically
This is a follow up from a question of mine that was just answered
This is a follow-on from a previous SO question Anchoring CSS Repeating Background Image

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.