views:

477

answers:

3

I have UIButton on the main view, when the button is clicked I add a UIImageView to the whole screen filling up the screen (this is added on top of the button).

What happens is that by clicking on the UIImageView's image (at the location where the UIButton is) it launches the UIButton click. However, since the button is invisible to the user and covered up by an image, this is not the desired behavior.

Has anyone had a similar thing happen? Any help is appreciated!

+2  A: 

Normally, UIImageViews should have their userInteractionEnabled property set to NO, so they shouldn't respond to touch events and shouldn't pass them on down the chain of views (effectively blocking touches from doing anything to views obscured by the images). I'm assuming that you're not resetting that property to YES, so it sounds like touches are not being handled by your image view.

One way that could happen is if the superview that you're adding the UIImageView to does not cover the whole screen. The UIImageView will spill over the superview's bounds and appear to be drawn over the whole screen, but will respond to touches only over the area of its superview.

Brad Larson
A: 

This may be more of a bandaid than a fix, but you could add a check of the UIImageView's state to the UIButton Click event, and just exit out of the event if the UIImageView is currently filling the screen.

Zemm
A: 

I actually got it to work by setting the frame with:

[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Instead of:

[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

It seems like having the applicationFrame instead of the bounds was the issue.

rksprst