What is an acceptable FPS for scrolling, and what

2019-03-11 01:19发布

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.

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.

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.

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.

EDIT:

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

8条回答
Anthone
2楼-- · 2019-03-11 01:50

I would do something called Lazy Loading, which doesn't load the images until they are actually seen.

Here's a great example on how to do so: http://www.cocoacontrols.com/platforms/ios/controls/mhlazytableimages

Good Luck!

查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-11 01:53

There are a few things you can do in general to get better table view performance:

1) Switch to Loren Brichter's method of drawing UITableViewCell's (for lack of a better link: http://www.therefinedgeek.com.au/index.php/2010/12/21/fast-scrolling-uitableview-updates-for-ios-4-2/)

Basically, all his code does is render all your cell content as one opaque UIView, which UITableView (and CoreGraphics) can very quickly blast onto a UITableViewCell

If you don't want to do all your cell design in drawRect:, you can still use nibs, but:

  • Make sure every subview is marked opaque
  • Don't have any transparent/semi-transparent subviews
  • Don't have any images with an alpha channel != 1.0f.

2) Don't let UIImageView do any scaling to display your image, give it a correctly-sized UIImage

3) If you're using iOS 5 and above, you can register a nib for a particular cell identifier. That way, when you call [tableView dequeueReusableCellWithIdentifier:], you are guaranteed to get a cell. Cell allocation is faster (according to Apple), and you get to write less code:

- (void)viewDidLoad {
    UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"MyCellIdentifier"];
}

// ...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"MyCellIdentifier";
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    // Commented out code is no longer needed
    //if (cell == nil) {
    //    cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    //}

    // setup cell

    return cell;
}

4) Displaying images downloaded from the web

  • Display a default image (something to look at while the real image is downloading)
  • Start the download on a separate thread (hint: use GCD's dispatch_async())
  • When the image comes in, cache it (hint: NSCache), and display it on the cell
    • Do all image downloading/caching off the main thread; the only thing you should be doing on the main thread is setting the image (remember UI code HAS to be on the main thread!)

You'll probably want to write an async-capable UIImageView (or use an existing library).

Stay away from EGOImageView, even though it has async downloading, it does cache lookup (which happens to be on disk, so that means costly disk IO) on the main thread before dispatching to a background thread for the download. I used to use it, but I ended up writing my own set of classes to handle this, and it's significantly faster.

-

Just follow these, and stuff other ppl have written here, and you'll have table views that scroll like glass in no time :)

查看更多
登录 后发表回答