user6820041
user6820041

Reputation: 1213

Preventing touches from happening behind a view?

I'm programmatically presenting a view ontop of my main view controller's view. On the view I'm programmatically presenting there are buttons. The problem comes when I tap on one of these buttons, I'm interacting with the view I've presented my view overtop of. For example, I've got some buttons behind the view I'm presenting, and if I tap in the view where the covered up buttons are, the code still is getting run for the buttons behind the view even though they're hidden behind.

The only way I can think to stop this is to add tags to each of the views within my presented view and then do some logic like "while I'm presenting this view, go through all of the subviews on the main VC, and if those tags don't equal any of the tags in the presented view, turn off user interaction"

It seems super common to present a view overtop of other buttons/views. Is there a better way to accomplish this?

Upvotes: 0

Views: 73

Answers (1)

matt
matt

Reputation: 534893

Turn on User Interaction Enabled for the covering view. Now touches cannot fall through to the covered buttons behind it.

Upvotes: 2

Related Questions