Determine whether UIView is covered by other views?

℡╲_俬逩灬. 提交于 2019-12-04 20:08:45

Conceptually, you want to iterate down the stack, unioning the paths of the cards into an accumulated path, and then checking that union path for equality with the next union path. In other words, if adding the next path down doesn't change the union path, then it must be completely obscured, and can therefore be removed. It might look something like this:

UIBezierPath* accumulator = nil;
for (UIView* cardView in [[[containingView subviews] copy] reverseObjectEnumerator])
{
    UIBezierPath* p = GetPathForView(cardView);
    UIBezierPath* next = PathByUnioningPaths(p, accumulator);

    if ([next isEqual: accumulator])
    {
        // This view is completely obscured, remove it
        [cardView removeFromSuperview];
    }

    accumulator = next;
}

This, of course, presumes the existence of the functions GetPathForView and PathByUnioningPaths. The former will be yours to write, based on however you create your card views. The latter will require some sort of bezier path boolean operation library. I found this one, which seems to have a fair bit of traction: https://bitbucket.org/martinwinter/vectorbooleancg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!