UIImageviews transparent image collision detection

I am looking for a pixel collision with two UIImageviews with transparency.

The check should be performed after dragging and dropping the UIView, and it should determine if the UIView overlaps another UIImageview. With CGRectIntersectsRect, only frames are compared. Maybe there is a solution to create a new UIImageview from the overlapped area and check if it has only transparency?

Perhaps someone has a different hint or solution?

+3
source share
1 answer

You can get the crossed rectangle of the frame from CGRectIntersectsRectand extract the alpha channel values ​​for the intersecting areas for both images, as described in Obtaining an alpha pixel value for UIImage . If both have nonzero alpha in the same position, a collision is detected.

0
source

Source: https://habr.com/ru/post/1791487/


All Articles