Hit Test for non-transparency in Swift

Discussion in 'iOS Programming' started by macRumorsUserX, Mar 3, 2015.

  1. macRumorsUserX macrumors newbie

    Feb 2, 2015
    I am trying to do a hit test on a image I have loaded into an UIimageView. the image is one object about 50x50 inside of a 300x300 frame. so essentially, its a 300x300 transparent png file with the an object in the middle.

    I only want a touch or tap to be registered when the user touches the object. not the actual transparent parts of the image.

    how can this be done in swift?
  2. waterskier2007 macrumors 68000


    Jun 19, 2007
    Novi, MI
    You should use the hitTest method and return the view if the touch was inside your "touch" area

    see here
  3. DennisBlah macrumors 6502


    Dec 5, 2013
    The Netherlands
    I use UIButtons with an image only.

    Only the non-transperant area will be triggering the function of the button.

Share This Page