objective-c – 使用UITapGestureRecognizer查找查看哪个子视图

objective-c – 使用UITapGestureRecognizer查找查看哪个子视图,第1张

概述当使用UIGestureRecognizer时,如何知道事件发生在哪个子视图中? 根据文档: A gesture recognizer operates on touches hit-tested to a specific view and all of that view’s subviews. 据我所见,’view’属性是 The view the gesture recognizer is 当使用UIGestureRecognizer时,如何知道事件发生在哪个子视图中?

根据文档:

A gesture recognizer operates on
touches hit-tested to a specific vIEw
and all of that vIEw’s subvIEws.

据我所见,’vIEw’属性是

The vIEw the gesture recognizer is
attached to.

这将是父视图。

解决方法 这将在事件的位置找到最内层的后代视图。 (请注意,如果该子视图有任何交互式内部私有孙代码,这段代码也会找到那些。)

UIVIEw* vIEw = gestureRecognizer.vIEw;CGPoint loc = [gestureRecognizer locationInVIEw:vIEw];UIVIEw* subvIEw = [vIEw hitTest:loc withEvent:nil];

在Swift 2:

let vIEw = gestureRecognizer.vIEwlet loc = gestureRecognizer.locationInVIEw(vIEw)let subvIEw = vIEw?.hitTest(loc,withEvent: nil) // note: it is a `UIVIEw?`

在Swift 3:

let vIEw = gestureRecognizer.vIEwlet loc = gestureRecognizer.location(in: vIEw)let subvIEw = vIEw?.hitTest(loc,with: nil) // note: it is a `UIVIEw?`
总结

以上是内存溢出为你收集整理的objective-c – 使用UITapGestureRecognizer查找查看哪个子视图全部内容,希望文章能够帮你解决objective-c – 使用UITapGestureRecognizer查找查看哪个子视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1087928.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存