1

I am trying to disable the TouchesEnded event in my Code when someone clicks on a button. And when the user clicks on another button the TouchesEnded should be activated again.

So for understanding what my app does, every time you click on the screen the text on the screen changes. But when the user clicks the Button a, this touch event should be disabled. And when the user clicks on button b it should be activated again.

i have already tried self.view.isUserInteractionEnabled = false , but then I am not able to click on the button to activate the userInteraction again.

Does anybody as an idea how to fix this problem?

Fabian Müller
  • 318
  • 2
  • 11

2 Answers2

0

From the behavior you're describing, I'm assuming that your button is a subview of the view that's toggling isUserInteractionEnabled? Setting that flag to false will prevent user interaction on the view's subviews as well. You can fix this by adjusting the view hierarchy so that your button and your self.view are siblings: aka create a container view that has both the button and your referenced self.view as children.

WongWray
  • 2,414
  • 1
  • 20
  • 25
0

It doesn't make sense to "disable the TouchesEnded event".

You need to enable or disable your buttons and let the events be sent as normal. Alternatively, as you say, you could use isUserInteractionEnabled=false to make a button no longer respond to taps.

Edit:

After rereading your post, I think I understand what you are saying:

  1. "every time you click on the screen the text on the screen changes" - this means clicking anywhere but on the buttons.

  2. "But when the user clicks the Button a, this touch event should be disabled. And when the user clicks on button b it should be activated again."

So you want button clicks to disable/enable taps elsewhere on the screen.

I would suggest using a tap gesture recognizer (UITapGestureRecognizer) attached to the content view for your view controller. Those trigger an action when they fire, and have an isEnabled property. If you set that to false the tap gesture recognizer will stop responding to taps.

Duncan C
  • 128,072
  • 22
  • 173
  • 272