Keyboard Animation Issues When Calling becomeFirstResponder within a Modal View Controller

前端 未结 5 1818
北荒
北荒 2020-12-13 23:11

I\'ve been having some issues with calling -becomeFirstResponder on a UITextField contained with a view controller that is presented modally. I cal

5条回答
  •  囚心锁ツ
    2020-12-13 23:55

    I believe you're having problems because you're effectively stacking animations. The keyboard view is contained by the modal view. The keyboard view is trying to animate its slide in transition within the context of a view which is itself animating a slide in transition. The keyboard animation is trying to hit a moving target.

    The pause is most likely the run time of the keyboard transition animation. I am fairly certain the the keyboard animation seizes priority from other animations so that it can drive the rearrangement of the UI e.g. scrolling a table so that the keyboard does not overlay the edited table row. In any case, the keyboard animation occurs within the context of the superview. This is especially true in the case of modal view.

    So, the keyboard view animates itself sliding in but because the superview is not actually visible yet, you see nothing. When the superview does slide in, the keyboard is already present because its animation was completed before the superview started its animation.

    In short, I don't think you can actual accomplish what you want to do. Instead, I think you will have to animate the modal view transition first, then run the keyboard animation or you will have to accept having the keyboard immediately visible.

    I think that Cirrostratus' suggest above is a good one. Use an image of the keyboard that will slide in with the modal view and then immediately swap it out with the real keyboard.

提交回复
热议问题