开发者

Cocoa NSRect OUTSIDE of an intersection

开发者 https://www.devze.com 2023-03-21 12:59 出处:网络
I have two rects that intersect. They have the same dimensions, the only difference is that one of them is lower down the screen than the other. I know there is a way to get the rect of their intersec

I have two rects that intersect. They have the same dimensions, the only difference is that one of them is lower down the screen than the other. I know there is a way to get the rect of their intersection, but that's not what I want. I actually want a new rect from the area that lies outside of their intersection.

The top part of the lower view intersects with the bottom part of the top view. The new rect should not have that area. I basically want a rect with the same origin and width as the bottom view, but without the part that intersect开发者_Python百科s with the top rect.

Thanks for the help.


CGRect intersectRect = CGRectIntersection(highestRect, lowestRect);

CGRect theRectYouWant = CGRectMake(0, 0, 0, 0);

if(!CGRectIsNull(intersectRect)) {
    theRectYouWant = 
        CGRectMake(lowestRect.origin.x,
                   intersectRect.origin.y + intersectRect.size.height,
                   lowestRect.size.width,
                   lowestRect.size.height - intersectRect.size.height);
}

Have a look on this page for more, Elbimio ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号