如何判断两个CGRect是否相交? [英] How to figure out if two CGRect intersect?

查看:580
本文介绍了如何判断两个CGRect是否相交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In -drawRect:我想检查提供的矩形是否与anotherRect相交。

In -drawRect: I want to check if the provided rect intersects with anotherRect.

我不擅长这种几何数学的东西,特别是英语,所以什么我想说的是:

I'm not good at this geometry math stuff and especially at english so what I want to say is:

如果桌面上有两张纸,其中一张完全覆盖另一张或者只是一小部分,那就是rectsIntersect =是。

If you have two sheets of paper on the desk, and one of them covers the other either completely or just a small portion, it is rectsIntersect = YES.

如何检查 rect anotherRect

推荐答案

使用 bool CGRectIntersectsRect(CGRect rect1,CGRect rect2);

Swift 3:

public func intersects(_ rect2: CGRect) -> Bool

示例: rect1.intersects(rect2)

这篇关于如何判断两个CGRect是否相交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆