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;