Jean
Jean

Reputation: 2625

UIImageView allows button beneath it to be touched

Am developing an iPhone App. When the user taps a button, displaying a semi-transparent UIImageView on a page (i.e. covering the whole page). Now, since the UIImageView is semi-transparent, the buttons beneath it are seen. Clicking on the buttons (though the UIImageView is on top of it) is causing the button-click to be processed ; but I want to stop this. When the UIImageView is on th e top, only touching UIImageView (which calls a method) should work ; touching anything beneath it shouldn't.

Upvotes: 2

Views: 617

Answers (6)

Anton K
Anton K

Reputation: 344

It would be better if you will add your semi-transparent imageView not to self.view but to your application's window. like this:

AppDelegate *delegate = (Appdelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window addSubview:yourImageView];

To remove yourImageView just use

[yourImageView removeFromSuperView];

Upvotes: 0

Minkle Garg
Minkle Garg

Reputation: 751

You can add a UIView on the click of a button and then add UIImageview as a subview of view. Then decrease the alpha of uiview.

Upvotes: 0

msk
msk

Reputation: 8895

your_semi_transparent_ImageView.userInteractionEnabled = YES;

Upvotes: 0

Javal Nanda
Javal Nanda

Reputation: 1838

You have following alternatives : First make sure that UIImageView is on top of button. Bring if front by using bringSubviewToFront

  1. You can disable userInteraction of UIImageView.
  2. If you have any action associated with UIImageView , then you can prefer UIButton over there instead of UIImageView and set your image as a background of UIButton , and add action you required to perform with this button.

Upvotes: 1

Neo
Neo

Reputation: 2807

Suppose yourImageView is your UIImageView above your button, do this,

[yourImageView setUserInteractionEnabled:YES];

Upvotes: 2

Chris
Chris

Reputation: 489

Hide and disable the buttons when the ImageView is shown:

[button setEnabled:NO]; // If you want the button not to respond
[button setHidden:YES]; // If you want the button not to be seen

Upvotes: -1

Related Questions