How to detect when the non-transparent part of an UIImage is in contact with another

Discussion in 'iOS Programming' started by Deemeehaa, Apr 18, 2014.

  1. Deemeehaa macrumors newbie

    Apr 18, 2014
    I am having trouble accomplishing something that I thought was going to be much easier. I am trying to run a method whenever a non transparent part of a picture inside a UIImage touches another non-transparent part of an image contained within a UIImage. I have included an example to help further explain my question.


    As you can see in the image above, I have two triangles that are both inside a UIImage. The triangles are both PNG pictures. Only the triangle is visible because the background has been made transparent. Both of the UIImages are inside a UIImageView. I want to be able to run a method when the visible part of the triangle touches the visible part of the other triangle. Can someone please help me?
  2. waterskier2007 macrumors 68000


    Jun 19, 2007
    Novi, MI
    If you set the image views to be UIViewContentModeScaleToFill, then you could have the UIImageViews touching each other, and the images would touch. This would only be if you know the size of the UIImages and set up your UIImageViews to be the same dimensions as the images you want to place inside of them
  3. teagls macrumors regular

    May 16, 2013
    I could completely be misunderstanding what you are asking for but it sounds like you want per-pixel collision between UIImages?

    i.e. you want to know when the pixels of one images collide/intersect with that of another image.

    If so per-pixel collision is pretty easy to do I am sure you can find material on the internet and I think SpriteKit uses it as well. Hope this helps.

Share This Page