获取 uiscrollview 触摸的触摸位置
我有一个 uiscrollview 作为 uiscrollviewcontroller 的元素,以及其他视图对象。当scrollView是顶部子视图时,图像按预期滚动和缩放。但是,我还需要获取触摸的屏幕位置,特别是当没有滚动操作时。 (我知道滚动过程中位置可能会发生变化,但这并不重要。)我还没有找到一种方法来做到这一点。在scrollviewcontroller实现中,我自定义了所有应该执行此操作的标准方法:“touchesShouldBegin...”、“touchesBegan:...”、“touchesEnded:...”等等。据我所知,当滚动视图是顶部子视图时,在触摸事件期间不会调用这些。我尝试将delayContentTouches属性设置为YES和NO,但这似乎没有什么区别。
作为替代方案,我尝试将 UIView 作为顶部子视图,然后尝试将触摸传递到现在底层的滚动视图。在此配置中,调用标准方法,我可以获取触摸位置,但我还没有找到将触摸传递给scrollView以便发生滚动的机制。执行诸如将触摸消息发送到特定的滚动视图或“超级”或仅将它们发送到 nextResponder 之类的操作并不能做到这一点。看来我可以使滚动工作或找到触摸的位置,但不能两者兼而有之,具体取决于“顶部”子视图是什么。
我怀疑这是微不足道的,但经过两周的挣扎,是时候消除我因无法做到这一看似最简单的事情而感到的尴尬了。我已经阅读了 stackoverflow 上的所有相关问题,尝试了大多数(如果不是全部)建议,但到目前为止,没有任何效果。我浏览了答案中建议的各种链接和参考资料,包括苹果的文档,但没有一个指出我理解中的差距。任何想法将不胜感激。
I have a uiscrollview as an element of a uiscrollviewcontroller, along with other view objects. The image scrolls and zooms as expected, when the scrollView is the top subview. However, I also need to get the screen location of the touch, in particular when there is no scroll action. (I understand the location may change during a scroll, but that's not important.) I haven't found a way to do that. In the scrollviewcontroller implementation I have customized all of the standard methods that should do this: "touchesShouldBegin...", "touchesBegan:...", "touchesEnded:...", and so on. As far as I can tell, none of these are being called during a touch event when the scrollView is the top subview. I've tried setting the delayContentTouches property to both YES and NO, and that doesn't seem to make a difference.
As an alternative, I've tried putting a UIView as the top subview and then tried passing the touches to the now underlying scrollView. In this configuration, the standard methods are called and I can get the touch location, but I haven't found a mechanism for the touches to be passed to the scrollView so scrolling occurs. Doing something like sending the touch messages to the specific scrollView, or to "super" or just sending them to nextResponder doesn't do it. It seems I can make the scroll work or find the location of the touch but not both, depending on what the "top" subview is.
I suspect this is trivial, but after two weeks of struggling, it's time to eat my embarrassment for not being able to do this seemingly simplest of things. I've read all of the related questions here on stackoverflow, tried most if not all of the suggestions, and so far, nothing has worked. I've looked through the various links and references suggested by the answers, including Apple's documentation, but none have pointed out the gap in my understanding. Any ideas would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论