用于音量控制的 UIPanGestureReconizer
我正在开发一个带有手势识别器的应用程序。我一直在努力让它发挥作用。我试图让 UIPanGestureReconizer 来检测用户何时在 UIImageView 上向上或向下滑动手指并调整 UISlider 来调整音量。我已经被这个问题困扰了好几天了。阅读文档和所有内容,我找不到任何关于我想做的事情。有人有什么建议吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用
translationInView:
方法来获取触摸的翻译。您可以根据此检查平移的方向并相应地更改滑块值。如果您不想处理方向检测,您可以查看滑动,但您可能会失去您期望的翻译精度(如果有的话)。还有一件事,您是否将
userInteractionEnabled
设置为YES
。对于图像视图,它默认设置为NO
。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
toYES
. It is set toNO
by default for image views.