4

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.

Jorge
  • 540
  • 6
  • 21

3 Answers3

10

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.

Adis
  • 4,512
  • 2
  • 33
  • 40
  • The first solution is not the problem. I have checked a hundred times everything I'm trying to interact with has `userInteractionEnabled`. In fact, watching your answer I have checked one more time. The second I also think it is not, because it has an appropiate size of almost entire screen. Maybe when I get the animation to show the container in the screen I am moving another layer and the button layer never reaches the screen? – Jorge Mar 06 '18 at 15:52
  • Do you have a scrollview somewhere in the hierarchy? – Adis Mar 06 '18 at 17:16
  • No sir! I have added another test container with a button inside and it works perfectly. I'm thinking that it is not working because initially is outside of the bounds of the view. Could this be possible? I'm going mad with this :( – Jorge Mar 06 '18 at 17:17
  • What are you animating? Transform, constraints or frame? Animating transform might create a behavior such as this. – Adis Mar 06 '18 at 19:02
  • I really dont know :/ I'm using Spring which is an animation library. I just animate the entire view, which contains the container view. However, I'm narrowing down the problem. If I put the container view outside the view, I mean in the root of the main view this misbehaviour is not happening. But this way I cannot constraint it to be outside the screen and move it with the wrapper view. mmmmm..... – Jorge Mar 06 '18 at 19:29
  • Yes :) Added your comment as the answer. Thank you very much! – Jorge Mar 06 '18 at 20:30
0

Finally, this misbehavior was because the wrapping view in my container was smaller than the container, but as these two were out of screen I didn't realise at first. Making the wrapping view big enough to fit the child container was the solution.

Sorry because at last this was a stupid question.

Thank you all

Jorge
  • 540
  • 6
  • 21
-1

If you use auto layout. You may check out your constraint is correct or not. Especially for biggerOrEqual and smallerOrEqual constraint still need a concrete constraint. eg:

width = 100@750

width <= superView.width@999

You should not forget the first constriant.

Jerome Li
  • 1,492
  • 14
  • 20