简体   繁体   English

Swift:如何判断myView与哪些UIView相交?

[英]Swift: How to tell which UIView(s) myView is intersecting with?

I have an array of 16 boxViews, which are present in random locations on my superview. 我有一个包含16个boxView的数组,它们存在于我的superview上的随机位置。 I am dragging myView which is a special subView. 我正在拖动myView这是一个特殊的子视图。 I need to be able to tell which boxView(s), myView is intersecting with, at any given time. 我需要能够在任何给定时间分辨出myView与哪个boxView(s)交叉。 How do I do achieve that? 我该怎么做呢?

Suppose you have boxViews that is an array of all the view in your super view. 假设您的boxViews是超级视图中所有视图的数组。 And all UIViews in boxViews have the same immediate super view. 和所有UIViewsboxViews具有相同的直接超视图。 And that myView is among the views in boxViews . myView是在视图中boxViews

let intersectedViews = boxViews.filter { $0 !== myView }
                               .filter { CGRectIntersection(myView.frame, $0.frame) }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM