iOS 8 UIView not moving up when keyboard appears

后端 未结 4 1713
甜味超标
甜味超标 2021-02-04 12:32

I am developing a chat app which has UITableView and a UIView containing a UITextField and a UIButton in it. I am using the f

4条回答
  •  遥遥无期
    2021-02-04 13:13

    I just ran into this and made a discovery I thought I would share. In iOS 8 layout passes for the sub views of the main view will be done whenever the keyboard is about to appear or about to go away. These passes do not get done on iOS 7. So if you try to animate a sub view of the main view in keyBoardWillShow or keyboardWillChangeFrame the animation will get undone by the layout pass and your sub views that you tried to animate will move back to their original position. That is why keyboardDidChangeFrame works to animate the subviews and keyboardWillChangeFrame does not.

    Something odd I noted as well is the timing of when these calls are made. It seems the first time that the keyboard appears after the app is launched, the call to keyboardDidChangeFrame happens too late to be able to animate with the keyboard so they slide up together, but on second and subsequent times the keyboard shows, the call to keyboardDidChangeFrame happens sooner and it seems you can actually animate the views along with the keyboard.

    I must note that I am using C# and Xamarin as my development platform for iOS, so this may be different when using Swift or Obj-C.

提交回复
热议问题