将滑动手势限制在特定区域 (iPhone)
我刚刚设法为我的应用程序实现滑动手势的检测。但是我想限制手势有效的区域。考虑到这一点,我想出了一个可能的解决方案,即检查启动和停止是否已启动。完成坐标在某个区域内。我只是想知道是否有更好或首选的方法来做这样的事情。
I have just managed to implement detection of a swipe gesture for my app. However I would like to confine the area where the gesture is valid. Thinking about this I came up with a possible solution which would be to check whether the start & finish coordinates are within some area. I was just wondering if there's a better or preferred method of doing something like this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需创建一个不可见的 UIView(= 具有透明背景)并设置其框架,使其包含您想要检测手势的区域。
然后,只需添加
UISwipeGestureRecognizer< /code>
到该视图,您就完成了。
阅读通用 UIGestureRecognizer 类参考 和 iOS 事件处理指南中讨论的部分
UIGestureRecognizers
了解更多信息。当然,您也可以使用自定义代码自行管理滑动手势的检测就像在这里解释的那样相同的指南,但当
UIGestureRecognizers
可以为您管理一切时,为什么还要麻烦呢?Simply create an invisible
UIView
(= with transparent background) and set its frame so it encloses the region you want to detect the gesture into.Then, simply add a
UISwipeGestureRecognizer
to that view, and you are done.Read the generic UIGestureRecognizer Class Reference and the part of the Event Handling Guide for iOS that talks about
UIGestureRecognizers
for more info.Of course you could also manage the detection of the swipe gesture by yourself using custom code like explained here in the very same guide but why bother when
UIGestureRecognizers
can manage everything for you?