Moving content located under the keyboard

删除回忆录丶 提交于 2019-12-06 15:31:07

I don't know how Apple does it, I believe they recommend to put the content into a scrollview then when you tap text field, you tell the scrollview to scroll up so you can see what you're typing.

I am a bit of a lazy person, so all I do is tell the view itself to shift up when user taps on a field that will be hidden by the keyboard.

I usually do this with:

// shift view up
self.view.transform = CGAffineTransformMakeTranslation(0, -someYOffsetValue);

// shift view back down to original value
self.view.transform = CGAffineTransformMakeTranslation(0, 0);

You can wrap this in a UIView animateWithDuration: block for a smooth transition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!