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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:26:57+00:00 2026-06-04T07:26:57+00:00

I’m trying to zoom the drawing on the context based on pinching in and

  • 0

I’m trying to zoom the drawing on the context based on pinching in and out. This is working perfectly, but it will always zoom from the origin (top left). This doesn’t give the nice effect you get in other applications and is really annoying. The old zooming method is as follows:

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

    if ([pinch scale] > zoomLevel + MAX_ZOOM_PER_CALL) {
        [pinch setScale: zoomLevel + MAX_ZOOM_PER_CALL];
    }

    if ([pinch scale] < zoomLevel - MAX_ZOOM_PER_CALL) {
        [pinch setScale:zoomLevel - MAX_ZOOM_PER_CALL];
    }

    float prevZoomLevel = zoomLevel;
    CGFloat factor = [pinch scale];
    zoomLevel = factor;

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

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

    //The next piece of code is added here

    [self setNeedsDisplay];
}

The actual zooming is done in the drawing methods of the parts that are shown on the context. I was thinking of changing the origin of the screen (that is the relative origin to the items that are to be drawn) so it would simulate this. But it is not working at all, this is what i have right now:

float dZoomLevel = zoomLevel - prevZoomLevel;

if (dZoomLevel != 0) {
    CGPoint touchLocation = [pinch locationInView:self];
    CGPoint zoomedTouchLocation = CGPointMake(touchLocation.x * prevZoomLevel, touchLocation.y * prevZoomLevel);
    CGPoint newLocation = CGPointMake(touchLocation.x * zoomLevel, touchLocation.y * zoomLevel);

    float dX = ( newLocation.x - zoomedTouchLocation.x );
    float dY = ( newLocation.y - zoomedTouchLocation.y );

    _originX += roundf(dX);
    _originY += roundf(dY);
}

The origin is taken from the xml (the smallest x and y of all the elements). It will usually be something between 12000 and 20000 but could in theory be between 0 and 100000.

I’m not sure if I’ve made myself clear, but if you need any information or don’t understand something just ask me and i’ll try to reply ASAP. Thanks in advance!

  • 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-04T07:26:59+00:00Added an answer on June 4, 2026 at 7:26 am

    I found the answer myself. The way one needs to zoom in my case is by zooming from the point of the touch. So when the x and y coordinates get zoomed do this:

    x -= pinchLocation.x;
    y -= pinchLocation.y;
    
    x *= zoomLevel;
    y *= zoomLevel;
    
    x += pinchLocation.x;
    y += pinchLocation.y;
    

    or in short:

    x = (x - pinchLocation.x) * zoomLocation + pinchLocation.x;
    y = (y - pinchLocation.y) * zoomLocation + pinchLocation.y;
    

    now x and y are on the correct location!!

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is

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.