获取 UISwipeGestureRecognizer - 自定义手势识别器的速度?
我有一个播放视频的应用程序。我想通过手势控制视频,即从左向右滑动可向前,从右向左滑动可向后。
我之前曾就该主题提出过问题,但当时该项目还只是一个想法。现在我要坐下来自己编码,我不知道该怎么做。
回答者补充说,我可能需要创建一个自定义手势识别器来获取滑动的速度,我希望这个速度能够影响视频的速度。
有什么想法我该怎么做吗?
我以前从未构建或配置过手势识别器,所以我不知道如何去做?
我真正想要的是一种处理开始和结束方法的方法。我想我可以在两者之间运行一个计时器并计算出 X 和 X 。 Y 计算速度。任何帮助、代码示例等都会有所帮助。
干杯
I have an app that plays a video. I want to control the video by Gesture i.e. swipe left-to-right for forwards and right-to-left for backwards.
I previously asked a question on the topic, but that was when the project was but an idea. Now I am to sit down and code the thing myself I have no idea what to do.
The answerer added that I may need to create a custom gesture recogniser to get the speed of the swipe, I wish this speed to affect the speed of the video.
Any ideas how I would go about this?
I've never built or configured a gesture recogniser before so I've no idea how to go about it?
What I really want is a way to handle the begin and end methods. I think I can get a timer running between the two and work out the X & Y to calculate the speed. Any help, code-samples and the like will help.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是计算
touchesBegan
和touchesEnded
之间的时间差和 x 位置差。使用这两个数字,您可以计算“每秒像素数”或类似的值。然后,您可以使用结果的大小作为视频速度的系数。One way would be to calculate the time difference and x-position difference between
touchesBegan
andtouchesEnded
. Using these two numbers, you can calculate "pixels per second", or similar. You can then use the magnitude of the result to act as the coefficient of the speed of the video.