1

I'm building app for kids with lots of interactive image objects (click on pic & get result)

For example: I have cat on my screen and with click on it I need to produce sound.

After having read lots of info I got the idea that it's almost impossible to transform certain parts of image to clickable objects.

While there are lots of games on the app store which contains lots of custom shaped clickable objects. How did they manage to do this?

What I need read to get the answer? Thank you in advance.

UPDATE: I can have my clipart images as vector-graphic, e.g. .svg file. Will it make the situation simpler?

Alex F
  • 183
  • 2
  • 14

3 Answers3

0

Implement each image as a UIButton and set the background of each button as the image desired. (setBackgroundImage)

Links: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/

Jack C
  • 1,044
  • 2
  • 12
  • 22
  • 1
    It will make "cat image" became rectangular from the point of clickable area. I need detect clicks within custom shape. – Alex F May 14 '15 at 16:29
0

Using images is one option, but if you want taps within a certain non rectangular shape, check out OBShapedButton

rounak
  • 9,217
  • 3
  • 42
  • 59
0

If you really want super accurate touches, you could construct a bezierpath in the shape of the image then use

[UIBezierPath containtsPoint:]

https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/instm/UIBezierPath/containsPoint%3a

You could also possibly get the pixel colour underneath the touch, but that wouldn't give much room for error if the user tapped near the edge:

https://stackoverflow.com/a/7101544/78496

Community
  • 1
  • 1
chedabob
  • 5,835
  • 2
  • 24
  • 44