GithubHelp home page GithubHelp logo

Comments (6)

jonathanhirz avatar jonathanhirz commented on June 25, 2024

confirming this, it makes the zoom 'reset' after lifting fingers/touches

from gesluxe.

josuigoa avatar josuigoa commented on June 25, 2024

@anissen told me about this issue too.

The problem is in this piece of code. It fires a CHANGE event when a finger/touch is lifted, catching it and getting the scale=1 value, because there is only one touch. If you put down the finger again, it will recognize the zoom event.

An option is to cancel the event. So, instead of firing the CHANGE event in that line, it would fire CANCEL and it could be handled in a different way. In this case, if you put down the finger again, it won't recognize anything, because the gesture is already cancelled. To get the gesture working again, you should 'restart' the gesture, lifting all the touches and putting them down again.

Another option is to check the touchCounter variable when handling the event. If the number of touches is less than 2, we can ignore it.

The last option is not to fire the CHANGE event it that line (neither call updateLocation), then you can put the touch down again and it would fire the CHANGE event again.

I don't know which one is the best option, I think there are a case for every option, what do you think? Probably I would choose the last one, but tell me what you think!

from gesluxe.

jonathanhirz avatar jonathanhirz commented on June 25, 2024

I actually was able to work around it for a transformGesture. I think I would only change if the scale != 1, and rather than directly setting the scale to match the gesture's scale, I saved the previous value and scaled that one...or something (it was a late night coding...). I'll post an example when I get close to my computer.

It sounds like the way it is has the least issues and are able to be worked around in code, so I would leave it as is

//edit - https://gist.github.com/jonathanhirz/7e0bef4904c0f19d05d3 - basically what I'm doing to get zooming working without resetting to 1 on each new touch/gesture

from gesluxe.

josuigoa avatar josuigoa commented on June 25, 2024

yeah, I use TransformGesture as well, but when I tested the ZoomGesture I wasn't very confortable with that 'resetting', that's why I wanted to 'fix' it.

Maybe I won't change until it's totally necessary.

from gesluxe.

jonathanhirz avatar jonathanhirz commented on June 25, 2024

here's my understanding of your code, and why it should actually stay as is: when you place two fingers down and begin a zoom or transform gesture, the scale is set to 1. As you pinch or stretch these two points, the scale changes accordingly. I think the error is in your sample project, where you directly set the zoom to this scale. It works, but as you said, this scale resets to 1 when a finger is lifted for underlying reasons. Rather than change the underlying code to 'fix' this, it is better to use this scale result in a better way. The sample I posted used a temporary variable to save the zoom of the camera on GESTURE_ENDED, and scale that before applying the zoom. I use this, and I don't have that snap back any more.

Hope that helped, I really like this library for my current project. =]

from gesluxe.

josuigoa avatar josuigoa commented on June 25, 2024

glad you like it!

you helped me a lot, thanks!

from gesluxe.

Related Issues (4)

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.