GithubHelp home page GithubHelp logo

Comments (3)

jasonpolites avatar jasonpolites commented on July 30, 2024

Hey,

This is actually a fairly complex task, even though it sounds simple. In order to zoom to a specific point on the image in an animation every "frame" of the animation has to do two things:

  1. Increase the scale by an amount proportional to the amount of time that has passed
  2. Move the center point of the image along a vector running on the OPPOSITE direction to the vector formed between the image center point and the touch point for a zoom.

The second part is the complicated bit. If you don't do this the image will "appear" to move outwards as it scales up because it always scales from the midpoint.

This is done in the pinch-zoom code here:

https://github.com/jasonpolites/gesture-imageview/blob/master/main/src/com/polites/android/GestureImageViewTouchListener.java#L196

If you wanted to do this I would put all your logic into the ZoomAnimation object. That is, the touch point (x,y) and the length of time you want the animation to last.

The "elapsedTime" parameter in the update() method of the animation gives you the total elapsed time since the animation started. So the position and scale should be based on this time vs. the length of time you want the animation to last.

I do plan to implement this at some point, and whenever that is I would most likely do this:

When the ZoomAnimation is started record the midpoint of the image and the touch point for the destination, then calculate the vector between the two. (using the VectorF object).

Once you have this you adjust its length then use it to calculate the expected x,y position for the NEW midpoint of the image. The amount the midpoint should be moved is calculated from the initial distance between the original midpoint and the touch point together with the scale. For example.. if the touch point is calculated at a distance of 100 from the midpoint of the image, and you want to scale by 150% then the scaled distance is 150, this means you have to move the image by 50 in the OPPOSITE direction to the vector between the midpoint and the touch point.

Confused yet? ;)

from gesture-imageview.

Vad1mo avatar Vad1mo commented on July 30, 2024

thank you for the outline. I will give it a try. Do I need to change something outside ZoomAnimation?

for exmple on double tap return e.g.?

        if(doubleTapDetector.onTouchEvent(event)) {
            initialDistance = 0;
            lastScale = currentScale;
            //lastScale = image.getScale();;
            currentScale = image.getScale();;
            next.x = image.getImageX();
            next.y = image.getImageY();
            calculateBoundaries();
            image.animationStart(new ZoomAnimation());
        }

from gesture-imageview.

jasonpolites avatar jasonpolites commented on July 30, 2024

Actually.. I've already implemented this. Just not quite finished. Will upload soon

from gesture-imageview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.