我已经在iphone模拟器上开发了一款应用数周了,到目前为止它一直运行得很好,但在加载内容和动画时突然开始运行很慢。自从上次测试成功以来,我没有对我的代码做任何更改。

我尝试重新启动模拟器(多次)和删除应用程序,并做一个完全干净的重建,但没有运气。在模拟器运行时,我还通过监视器检查了我的cpu使用情况,我只使用了大约30%的cpu和40%的内存。

我完全理解模拟器从来没有设备本身那么快,但它在这么长时间后突然开始变慢,这似乎很奇怪,我所说的慢是指不到原始速度的四分之一。


当前回答

这不仅仅是关于慢动画。Xcode模拟器的全局性能非常低。这是苹果的漏洞。我已经通过反馈助手报告了。我已经用代码创建了演示,演示模拟器比任何旧的实际设备慢200倍。我发现JavaScript代码与日期对象执行在WKWebView是模拟器的痛苦。改变模拟器中的选项在我的情况下没有帮助。查看jsfiddle https://jsfiddle.net/kjms16cw/我希望苹果能尽快修复它!

var log = document.getElementById("log"); document.getElementById("button").onclick = function() { run(); }; function run() { var d1 = new Date(); for (var i = 0; i < 1000; i++) { var x = new Date(); x.setMilliseconds(0); x.setSeconds(0); x.setMinutes(0); } var d2 = new Date(); log.innerHTML = ((d2.getTime() - d1.getTime()) / 1000) + " seconds"; } <h3>Xcode Simulator Extremely Low Performance</h3> <p>This test runs fast (several tens milliseconds e.g. 30 ms) in any browser any device any platform including very old iOS device e.g. iPhone 5C and several years old iPad 2, BUT IN SIMULATOR IT TAKES 6000 ms (yes, 6 seconds!). Terrible!</p> <button id="button">run()</button> <div id="log"></div>

其他回答

如果Cmd-T(慢动画)选项不适合您,并且调试->慢动画是关闭的,但您仍然有慢动画,请尝试模拟器->重置内容和设置(或可能是硬件->擦除所有内容和设置)。这里的其他答案都没用的时候,这个答案对我有用。有人知道为什么吗?

此外,附加调试器(完全)可能会使动画非常缓慢。

这不仅仅是关于慢动画。Xcode模拟器的全局性能非常低。这是苹果的漏洞。我已经通过反馈助手报告了。我已经用代码创建了演示,演示模拟器比任何旧的实际设备慢200倍。我发现JavaScript代码与日期对象执行在WKWebView是模拟器的痛苦。改变模拟器中的选项在我的情况下没有帮助。查看jsfiddle https://jsfiddle.net/kjms16cw/我希望苹果能尽快修复它!

var log = document.getElementById("log"); document.getElementById("button").onclick = function() { run(); }; function run() { var d1 = new Date(); for (var i = 0; i < 1000; i++) { var x = new Date(); x.setMilliseconds(0); x.setSeconds(0); x.setMinutes(0); } var d2 = new Date(); log.innerHTML = ((d2.getTime() - d1.getTime()) / 1000) + " seconds"; } <h3>Xcode Simulator Extremely Low Performance</h3> <p>This test runs fast (several tens milliseconds e.g. 30 ms) in any browser any device any platform including very old iOS device e.g. iPhone 5C and several years old iPad 2, BUT IN SIMULATOR IT TAKES 6000 ms (yes, 6 seconds!). Terrible!</p> <button id="button">run()</button> <div id="log"></div>

我认为你错误地按了command + T而不是command + R。

您可以尝试关闭远程调试(Cmd-D ->停止远程JS调试)。这通常会加快速度。

I don't have the rep yet to leave a comment, but I upvoted some answers here and wanted to say more. I had a problem with slow animations in the iOS Simulator, especially on rotation, and I found this post via Google. Indeed, somehow "Toggle Slow Animations" must have been on, because three shifts fixed it. At first, I didn't think this was a problem because there's no checkmark next to "Toggle Slow Animations." It turns out there's never a checkmark, or any indication from the menu whether it's on or off. So just try toggling it and see if the rotation/navigation is faster/slower.

所以,谢谢大家!