CALayer 性能与 UIImageView 性能

CALayer performance vs. UIImageView performance(CALayer 性能与 UIImageView 性能)

本文介绍了CALayer 性能与 UIImageView 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm noticing that some of the things that I do with images in my app, I could be doing with CALayer properties instead (i.e. borders, shadows, gradients, and so on). So I'm wondering, in general, is it a better idea to use CALayers and such, or just do all that stuff in photoshop and use UIImage(View)s for whatever I need? Scrolling performance has been kinda slow with drop shadows and stuff, so I'm basically trying to find every little optimization that I can.

Background information: I'm basically just scrolling through a bunch of images, vertically. Somewhat like the photos app. This is all from 3.2 onwards, so I have access to things like the shadow and shouldRasterize properties in CALayer.

解决方案

A key thing to know about CALayer shadows is that they are, by default, rendered from the layer's composited alpha channel; that can be really slow, particularly when the layer is rotating or changing size. You should look into the shadowPath property: if you give Core Animation a simple shape, such as a rectangle (UIBezierPath +bezierPathWithRect: with the layer's bounds will give you [via its CGPath property] a CGPathRef you can use there), you'll see much better performance.

shouldRasterize is also definitely useful, particularly with views that have many subviews that don't change often; make sure, though, that you set the layer's rasterizationScale to [UIScreen mainScreen].scale, or you'll get some nasty pixelation on high-resolution screens like the iPhone 4's.

这篇关于CALayer 性能与 UIImageView 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:CALayer 性能与 UIImageView 性能

基础教程推荐