简体   繁体   中英

What would be the reverse of CGRectUnion()?

I can combine rect1 with rect2 using CGRectUnion() and get a combined rect3 fine.

Is it possible to subtract a rect1 from a rect3 (which contains rect1) and get a remaining part of 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).

If you were programming the Mac, I would suggest using another API named HIShape . It's the modern successor to QuickDraw Regions, and as such, it is capable of non-rectangular shapes. Unfortunately, though HIShape is still available on 64-bit Mac OS X, it is not available on 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.

如果我可以正确理解,请尝试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. You could obtain a rect just in case rect3 and rect1 share completely a side and have it (all of it) in common. 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? or slit the resuting area in more CGrect (upper rect, left, bitton, right...) what are you going to do with the resulting "object"?

luca

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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