什么是可接受的滚动FPS,以及提高性能的提示有哪些? [英] What is an acceptable FPS for scrolling, and what are tips for improving performance?

查看:89
本文介绍了什么是可接受的滚动FPS,以及提高性能的提示有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多WWDC视频中看到,你希望尽可能接近60.0 FPS以获得更好的平滑滚动体验。我有一个UIScrolLView,它可以同时加载图像和几个表视图。目前我获得30 FPS。这是推荐的FPS的一半。只是想知道你们通常会得到什么FPS的桌面视图/滚动视图加载图像和其他沉重的东西/渲染的东西。

I see in many WWDC video's that says you want to achieve 60.0 FPS as close as possible to get a better smooth scrolling experience. I have a UIScrolLView which loads up image and a couple of table view's at once. Currently I am getting 30 FPS. This is half of what the recommended FPS. Just wondering what FPS do you guys typically get for a table view/scroll view that loads up images and other heavy stuff/rendering stuff.

任何其他的优化FPS的技巧?我花了一周的时间,直到现在使用时间分析器,分配和核心动画工具启动仪器,以尽可能地优化。

Any other tips for optiziming FPS? I've spend the past week till now firing up Instruments using the time profiler, allocations, and core animation tool to optimize as much as I can.

只是为了澄清一个咬我的东西。我在iPad上有一个砖石/瀑布/ pinterest风格的布局。所以它不仅仅是一个普通的UITableView。它是一个UIScrollView,可以填满整个屏幕,并且充满了几个UIView。每个视图都有一个150x150的UIImageView和一个UITableView,还有一些使用Core Text绘制的属性标签。因此,当您看到屏幕时,您可以一眼看到5-8表格视图,每个单元格再次具有UIImageView,然后每个单元格渲染使用核心文本绘制的属性标签。

Just to clarify a bit on what I have. I have a masonry/waterfall/pinterest style layout on the iPad. So it's not just a regular UITableView. It's a UIScrollView that fills out the whole screen, and is filled with a couple of UIView's. Each of this view has a 150x150 UIImageView and a UITableView and also it has some attributed label, drawn using Core Text. So at one glance when you see the screen, you can see 5-8 table view at one shot, each cell again has a UIImageView and then each cell renders attributed label drawn using core text.

所以你可以想象这是多么深刻和复杂。这不仅仅是带有UIImageView的常规表视图。我知道如何在带有UIImage的iPhone中只使用一个UITableView获得60 FPS。这个概念是异步加载图像,而不是尽可能地阻止主线程。

So you can just image how deep and complicated this is. This is not just a regular table view with a UIImageView. I know how to get 60 FPS with just one UITableView in an iPhone with a UIImage. The concept is to load images asynchrounously and not to block the main thread as much as possible.

编辑:

这里的问题似乎是我在视图中的UITableView ..当我从UIView中删除它时,我得到了非常流畅的滚动..

It seems that the problem here is the UITableView that I have inside my view.. when I remove that from the UIView I get really smooth scrolling..

我上传了一个示例项目,这是我所拥有的更简单的版本,但它清楚地显示了问题。该链接是此处

I uploaded a sample project which is a simpler version of what I have, but it clearly shows the problem. The link is here

推荐答案

很多事情会影响渲染性能,这里有一些你可以检查的项目:

Many things affect render performance, here are some items you can check:


  • 简介 - 你说你已经这样做了,太棒了!不幸的是,分析经常被忽略,即使它可以揭示意外问题。在一个应用程序中,我正在使用表示日期的不同单元格的日历。首先在单元格之间滚动缓慢,这是出乎意料的。我想也许是在绘制一些细胞太多了。在分析后,我发现 [NSCalender currentCalender] 使用了85%的CPU时间!修好之后一切都滚动得很棒!

  • Profile - You said you already did this, so great job! Unfortunately profiling is often overlooked, even though it can reveal unexpected problems. In one app I was working on a calendar with different cells representing dates. At first scrolling between cells slow, which was unexpected. I thought maybe it was drawing a few cells too many. After profiling I found that [NSCalender currentCalender] was using 85% of my CPU time! After fixing that everything scrolled great!

图像 - 大图像在CoreGraphics中加载了很多。滚动尤其需要大量的绘制操作来移动它们。一个提示是尽可能少地在设备上缩放图像,这使得CoreGraphics的工作变得更加容易。如果图像的大小是显示它的视图的两倍,请在视图中显示之前调整UIImage的大小。 iOS设备最适合处理PNG。它们在编译时由工具(pngcrush)压缩,iOS具有用于渲染它们的特殊硬件。

Images - Large images put a lot of load in CoreGraphics. Scrolling especially requires a lot of draw operations to move them around. One tip is to scale images on the device as little as you can, that makes CoreGraphics' job a lot easier. If an image is twice as large as the view displaying it, resize the UIImage before displaying it in the view. iOS devices handle PNGs best. They are compressed by a tool (pngcrush) at compile time and iOS has special hardware for rendering them.

编辑:JPG可能是照片的更好选择。 iOS设备也有专门的JPG解码器。

Edit: JPGs are probably a better option for photos. iOS devices have dedicated JPG decoders as well.


  • 自定义绘图 - 如果可能的话,减少你自己定制的CGContext绘图量。大量自定义绘图对动画速度有负面影响。如果可能的话,我会考虑在复杂的自定义绘图上使用图像。

  • Custom Drawing - If possible, cutback on the amount of custom CGContext drawing you do. Lots of custom drawing has negative effects on animation speed. I would considering using an image over complex custom drawing, if possible.

剔除 - 只绘制你需要的东西。 UITableView 会自动卸载并加载出现的单元格,因此您可以这样做,但任何自定义CGContext绘图都应该在该部分可见时完成。根据我的经验,自动查看阴影也可能非常慢。

Cull - Only draw things you need to. UITableView automatically unloads and loads cells as they appear, so this is done for you, but any custom CGContext drawing should only be done when that part is visible. Also automatic view shadows can be very slow in my experience.

重用 - 在 UITableView上使用重用标识符,这将允许 UITableView 重用单元格对象,而不是在滚动时重新分配 - 查看答案问题。还要重用 UIImages ,而不是为同一个文件分配多个。 imageNamed 自动缓存图片但 imageFromContents 的文件没有。

Reuse - Use the reuse identifier on UITableView, this will allow UITableView to reuse cell objects rather than reallocating as it scrolls - look at the answer to this question. Also reuse UIImages rather than allocating multiple for the same file. imageNamed caches images automatically but imageFromContents of file does not.

创建自己的 - 您可以创建自己的网格视图类,剔除屏幕外隐藏的子视图视图,并滚动延迟内容加载。通过编写自定义解决方案,您可以完全控制流程并创建针对使用上下文进行优化的设计。对于大多数用例,您将很难构建比Apple标准更好的东西,但我已经看到它在特定情况下完成。

Create your own - You could create your own grid view class that culls it's subviews views hidden off screen, and scrolls with lazy content loading. By writing a custom solution you can fully control the process and create a design optimized for the usage context. For most use cases you will have a hard time building something better than the Apple standard, but I have seen it done in specific cases.

最后的手段 - 减少有问题的视图的大小(改善滤液),将内容分成多个页面,缩小图像尺寸,剪掉不具备的旧设备表现也很好。在牺牲大部分内容之前我会满足30 FPS。设备将继续变得更快,旧设备将被淘汰,您的应用将逐渐加快。

Last resort - Reduce the size of the offending view (improves filtrate), break content into multiple pages, downsize images, cut out older devices that don't perform as well. I would settle for 30 FPS before sacrificing most of that stuff. Devices will continue to get faster, older devices will be eliminated, and your app will gradually get faster.

这篇关于什么是可接受的滚动FPS,以及提高性能的提示有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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