首次出现键盘时的动画有时不流畅 [英] Animations during first keyboard appearance is sometimes not smooth

查看:83
本文介绍了首次出现键盘时的动画有时不流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常注意到,在第一次出现键盘时,在第一次成为firstFirstResponder事件期间,UIView动画通常不平滑。我指的是与键盘动画一起发生的动画,例如手动滚动UIView以使textField可见。动画在首次执行后始终是平滑的。

I have often noticed that UIView animations are often not smooth during the first becomeFirstResponder event when the keyboard appears for the first time. I am referring to animations that occur with the keyboard animation, such as manually scrolling the UIView to make a textField visible. The animation is always smooth after the first time it is executed.

是否存在技术原因?我当时认为UIView动画在第一次运行时可能会发生一些延迟加载或优化,然后将其存储在缓存中以供重用。是否有关于此的经验教训?如果听众不清楚,我可以尝试在测试项目中重新创建问题。

Is there a technical reason why this would be the case? I was thinking that there might be some lazy loading or optimization that happens with UIView animations on the first run, then gets stored in cache for reuse. Are there lessons learned around this? If this is not clear to this audience, I can try to recreate the issue in a test project.

推荐答案

虽然这不能回答为什么会发生的问题,但它说明了解决方法。

While this does not answer the question WHY this happens, it explains how to fix it.

为什么iOS动画在首次运行时会变慢?

基本上,您需要对 DID事件进行动画处理,而不是将或应该。系统在将/应该事件期间执行其动画,因此显然存在一些勾结。这不能解释为什么第一次运行和所有其他运行之间的行为不一致。

Basically, you need to do animations on "DID" events rather than "WILL" or "SHOULD". The system performs it's animations during the "will/should" events, so apparently there is some colluding happening. This does not explain why the behavior is inconsistent between the first run and all other runs.

我想像你们中的某些人一样,应该将动画放在 textFieldWillBeginEditing中,因为我希望动画可以与键盘动画同时运行。幸运的是,将动画代码置于 DID实际上仍然可以确保动画同时发生。太棒了

I thought, as may some of you, that I should put the animation in the "textFieldWillBeginEditing" because I wanted the animation to run concurrently with the keyboard animation. Luckily, putting the animation code in "DID" actually still ensures that the animation happens concurrently. Fantastic.

如果仍然有人对首轮和后一轮之间的不一致有一个解释,我仍然会公开他的问题,并给您奖励和回答。谢谢!

If anyone still has an explanation of the inconsistency between the first and latter runs, I'll still hold his question open and award you with an upvote and question answer. Thanks!

这篇关于首次出现键盘时的动画有时不流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆