Hit Test for non-transparency in Swift

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

  1. macRumorsUserX macrumors newbie

    Joined:
    Feb 2, 2015
    #1
    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

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    You should use the hitTest method and return the view if the touch was inside your "touch" area

    see here
     
  3. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    I use UIButtons with an image only.

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

Share This Page