简体   繁体   English

CGRectUnion()的反面是什么?

[英]What would be the reverse of CGRectUnion()?

I can combine rect1 with rect2 using CGRectUnion() and get a combined rect3 fine. 我可以使用CGRectUnion()将rect1与rect2结合起来,并得到一个结合好的rect3。

Is it possible to subtract a rect1 from a rect3 (which contains rect1) and get a remaining part of rect? 是否可以从rect3(包含rect1)中减去rect1并获得rect的剩余部分?

As Brad Larson said, you can't do this in Quartz, because the CGRect functions work with nothing but rects and their component parts (points, sizes, and single numbers). 正如布拉德·拉尔森(Brad Larson)所说,您无法在Quartz中做到这一点,因为CGRect函数只能使用rect及其组成部分(点,大小和单个数字)工作。

If you were programming the Mac, I would suggest using another API named HIShape . 如果您正在为Mac编程,我建议您使用另一个名为HIShape的 API。 It's the modern successor to QuickDraw Regions, and as such, it is capable of non-rectangular shapes. 它是QuickDraw区域的现代继承者,因此,它可以具有非矩形形状。 Unfortunately, though HIShape is still available on 64-bit Mac OS X, it is not available on iOS. 不幸的是,尽管HIShape仍在64位Mac OS X上可用,但在iOS上不可用。

If you really need something like this, you will have to write it yourself, including your own HIShape-like not-necessarily-rectangular shape class. 如果您确实需要类似这样的内容,则必须自己编写,包括自己的类似HIShape的不必要的矩形形状类。

如果我可以正确理解,请尝试CGRectIntersection。

well, it depends... on how rect3 contains rect1... i mean, it may happens that the resulting area is no more a rect... for example, if rect1 is all inside rect3 the remaining area is not a rect, so you couldn't use the CGRect object. 好吧,这取决于... rect3包含rect1的方式...我的意思是,结果区域可能不再是rect ...例如,如果rect1全部位于rect3内,则其余区域不是rect,因此您不能使用CGRect对象。 You could obtain a rect just in case rect3 and rect1 share completely a side and have it (all of it) in common. 您可以得到一个rect,以防rect3和rect1完全共享一面并将其(全部)共有。 So i need to know what kind of objet you wanna obtain by that subtraction... may it be a new image with 2 different areas coloured? 因此,我需要知道通过该减法您将获得哪种对象……这可能是一张带有2个不同颜色区域的新图像吗? or slit the resuting area in more CGrect (upper rect, left, bitton, right...) what are you going to do with the resulting "object"? 还是在更多的CGrect区域(上矩形区,左侧,Bitton区,右侧区)中分割重排区域,您将如何处理生成的“对象”?

luca 卢卡

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

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