2

I'm trying to make my first game using SpriteKit + Swift.

The problem I'm trying to solve right now is that if I add to my main SKView a SUBVIEW without any buttons just with a background color and size and touch it, my main view handles this touch like there is no subview at all.

So the subView of type UIView like doesn't exist for UITapGestureRecognizer of parent view. And the only way I found to solve it, is to put a subView-sized button on the subview without text and handler. But this way looks creepy...

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Nikolay Pryahin
  • 377
  • 5
  • 19

1 Answers1

0

It could be that your subView (or one of its parents views) has the userInteractionEnabled set to false. UIView has the userInteractionEnabled set to true by default, but for example UIImageView (which is a subclass of UIView) has the userInteractionEnabled set to false by default.

When set to NO, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value of this property is YES.

(...)

Note

Some UIKit subclasses override this property and return a different default value. See the documentation for that class to determine if it returns a different value.

See Apple docs for more info.

It could be not your subView by itself, but one of its parents views too, because this setting is propagated down.

If set to NO, this view (along with its subviews) is excluded from receiving touches. Touches on this view or one of its subviews "fall through" to a view behind it.

source: Programming iOS by Matt Neuburg

For more, check On iOS, if a superview's userInteractionEnabled is NO, then all subviews are disabled as well?

Community
  • 1
  • 1
Mikolaj
  • 802
  • 10
  • 18