0

I'm a newbie in iPhone development and now encounter a problem:

I want to add a small hotspot on a large image and simply came up with the idea that I can add a button in that area setting alpha 0 to hide the button. Unfortunately, the phone does not response click events any more. Instead, if I increase the alpha, I can receive click events without any problems. So I wonder in which order does iPhone draw controller on the screen. Is it because my background image is drawn after the button if I set alpha of button too low, so the click event is intercepted by the background image?

Any hints will be highly appreciated. Thank you all in advance!

Best Regards.

Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83

2 Answers2

1

Set the button's style to Custom; the button will not be drawn, but should remain fully active.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • Thanks Marcelo. But why simply setting the alpha value does not work? – Summer_More_More_Tea Dec 09 '10 at 15:47
  • 2
    Because the UI framework treats invisible buttons as inactive. A Custom button isn't invisible, technically speaking; it just doesn't draw itself. The purpose of "Custom" is so you can assign an image or override `drawRect:`, i.e., do your own custom drawing. But if you do neither, you effectively create a "visible" button that you can't see. – Marcelo Cantos Dec 09 '10 at 15:50
1

The problem is not the order in which the views are drawn, it's rather that if a view's alpha is 0 it does not receive touch events. it's like the view is not there at all.

but you don't have to set the alpha to 0 on the UIButton, you can simply make it a Custom button instead of a Rounded Rect button. it'll be invisible and still work.

filipe
  • 3,370
  • 1
  • 16
  • 22