Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons inside container view does not work

Tags:

xcode

ios

swift

I am a total noob developing iOS applications and I'm working in one right now.

I have set up my storyboard with a HomeViewController (main) and inside this, a container view, with another view controller embeded. This child view controller is outside the bounds of the view, and when a click a button in my HomeViewController it gets animated to the top of my app, showing this child with a cool animation. Everything is right.

In my child view controller I only have 3 buttons, and when they are displayed on the screen with this little animation, they are not usable. They don't trigger the action of the button being pressed nor they get "highlighted" with iOS style. Nothing happens.

I have been searching a lot about this, I have tried addChildViewController() on parent, didMove(toParentViewController: UIViewController) on child and I also have added it programmatically. When added programmatically it works OK but the view does not respect the animation, just being displayed in the screen without following the parent's container, which indeed moves with the animation.

What should I do next?

Thank you very much

Edit: My question does not seem to be a duplicate of UIView animations canceling any touch input

I'm using Spring library for the animations. Also, in that thread they are talking about user interaction being blocked while animation isn't finished. That is not my case. Animation is perfectly finished when trying the button interaction.

like image 902
Jorge Avatar asked Jan 03 '23 17:01

Jorge


1 Answers

From my experience, there are two issues which cause this behavior most often:

  1. Some of your container views have userInteractionEnabled set to false, or
  2. Your container view frame is small and you're attempting to tap a button outside the frame of the container which won't work. Consider it like a window to the button and there's an invisible wall blocking touches.

Both of these are best debugged using the Xcode Debug View Hierarchy, or you can also try the Reveal app and see what's going on there.

like image 58
Adis Avatar answered Jan 14 '23 23:01

Adis