Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom gesture's last value is always 1 #2

Closed
josuigoa opened this issue Feb 19, 2015 · 6 comments
Closed

Zoom gesture's last value is always 1 #2

josuigoa opened this issue Feb 19, 2015 · 6 comments

Comments

@josuigoa
Copy link
Owner

At the end of the zoom gesture it always returns 1 value

@jonathanhirz
Copy link

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

@josuigoa
Copy link
Owner Author

@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!

@jonathanhirz
Copy link

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

@josuigoa
Copy link
Owner Author

josuigoa commented Jul 6, 2015

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.

@jonathanhirz
Copy link

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. =]

@josuigoa
Copy link
Owner Author

glad you like it!

you helped me a lot, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants