0

I have a question regarding touch or tap in xcode.

I was wondering if anyone could help me figure out how to make an image appear when the user taps the screen, and disappear when they lift their finger. For example when they're holding down their finger, a smiley face might show underneath it, and when they lift, it disappears.

I appreciate the help, thank you.

Brejuro
  • 3,421
  • 8
  • 34
  • 61
  • Use this - http://stackoverflow.com/questions/14856906/touchesbegan-touchesended-touchesmoved-for-moving-uiview. Add your show image code in touchesbegan and hide it touches ended – Sam B Jun 06 '14 at 16:43

2 Answers2

0

Give a look at UIPanGestureRecognizer. You can associate it to a UIImageView and define its handler method so that then it is in the begin phase, the image is shown; in the end phase, the image is hidden.

I hope this gives you a clue as to one way to go.

Add some of your code if you need more help, please.

sergio
  • 68,819
  • 11
  • 102
  • 123
0

The easiest way to do this would be to create an invisible button.

Set it's type to "Custom" and the size to the size of your image.

Select "Default" under "State config" in the attributes selector and make sure there's no image selected. Then select the state config "Highlighted" and select your image. When I did this the button size jumped back to the default for some reason, and I had to set it back to my desired size.

Once you've done this the buttons switches to it's highlighted state when you touch it, and your image appears.

You can attach an IBAction to the button or not, as desired.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Would this interfere with anything its over? I need this image to appear over another button that the user is pressing which would mean two buttons stacked on top of each other, one the invisible and one the original picture. – Brejuro Jun 06 '14 at 15:36