UIPanGestureReconizer for Volume Control
-
27-10-2019 - |
题
I'm working on an app with gesture recognizers. I'm stuck on trying to get this to work. I am trying to get a UIPanGestureReconizer to detect when the user slides the finger up or down on the UIImageView and adjust a UISlider which would adjust the volume. I have been stuck on this for a few days. Read docs and everything, I couldn't find anything on what I'm trying to do. Anyone have any suggestions?
Thanks
解决方案
You should be able to use translationInView:
method to get the translation of the touch. You can check the direction of the translation based on this and accordingly alter the slider value. If you don't want to handle the direction detection, you can look at swipes but you will probably lose the precision that you are expecting of a translation if any.
And one more thing, did you set userInteractionEnabled
to YES
. It is set to NO
by default for image views.