簡體   English   中英

如何判斷兩個CGRect是否相交?

[英]How to figure out if two CGRect intersect?

In -drawRect:我想檢查提供的rect是否與anotherRect相交。

我不擅長這種幾何數學的東西,尤其是英語,所以我想說的是:

如果桌面上有兩張紙,其中一張完全覆蓋另一張紙,或者只是一小部分,則rectsIntersect = YES。

如何檢查rectanotherRect

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

斯威夫特3:

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

示例: rect1.intersects(rect2)

嘗試使用此..在動畫imageview時,您可以通過以下方式獲取其實際幀:

[[obstacle1.layer presentationLayer] frame];

因此,它很容易使兩個imageview碰撞

if (CGRectIntersectsRect([[obstacle1.layer presentationLayer] frame], [[bgImageView.layer
    presentationLayer] frame])) 
{

    NSLog(@"Collision 1");

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM