iOS UIImageView使用(转自Apple doc)

本文提供优化ImageView性能的策略,包括提供预缩放图像、限制图像大小、禁用不必要的透明度渲染等,以提高用户体验。

Optimizing Image View Performance

Image views can perform two operations that are relatively expensive performance-wise: scaling the image and alpha compositing the image with lower layers. To maximize performance, you should:

  • Provide pre-scaled images where possible. For example, if you expect certain large images to be frequently displayed in a scaled-down thumbnail view, you might consider keeping the scaled-down images in a thumbnail cache.

  • Limit image size. Consider pre-scaling or tiling large images. The MVCNetworking sample code project (QImageScrollView.m) demonstrates how to determine what model of iOS device your software is running on. You can then use that information to help you determine what image dimension thresholds to use when scaling or tiling.

  • Disable alpha blending except where needed. Unless you are intentionally working with images that contain transparency (drawing UI elements, for example), you should generally mark the view as opaque by checking Opaque checkbox in the attributes inspector, or setting the opaque property on the view itself.

    For views that are not opaque, the device must perform a lot of unnecessary computation if alpha blending is enabled and the image contains an alpha channel. This performance impact is further magnified if you are using Core Animation shadows, because the shape of the shadow is then based on the contents of the view, and must be dynamically computed.

    1.userInteractionEnabled

    默认是NO,不接受用户事件,如果需要,则需要设置为YES

    2.animationImages

    实现动画,但是应该使用以下方式(参照上文):

    animationImageView = [[UIImageView alloc] init];

    UIImage *image = [UIImage imageNamed:@"a1"];

    animationImageView.frame = CGRectMake(x, y, image.size.width, image.size.height);

    NSArray *images = @[[UIImage imageNamed:@"a1"],[UIImage imageNamed:@"a2"], [UIImage imageNamed:@"a3"]];

    animationImageView.animationImages = images;






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值