In the UI interaction design of iOS, the processing of images is unavoidable, and different processing methods will have different influence on the internal;
************************************************************
A: Picture format and NSBundle loading full path:
1 "Xcode or the official Apple is highly recommended to use the image format is PNG
2 "All if you use a PNG image in your project, you do not have to write the suffix name
3 "Other formats require suffix, especially when loading images with UIImage
NSBundle Common code for loading full paths:
?
| 1 2 3 4 |
// 得到文件的路径 NSString *fullPath = [[NSBundle mainBundle] pathForResource:namePic ofType:nil]; // 从路径中读取图片UIImage *newImg = [[UIImage alloc] initWithContentsOfFile:fullPath]; |
************************************************************
B: Take Tom Cat as an example, look at two different forms of picture loading of uiimage
Tom Cat used to be a frame-by- sequence animation: The background is a full screen uiimageview, and then Uiimageview in a picture of the switch;
1 _tomlist is a property of a class of type Uiimageview, then the steps to play a frame-by- sequence animation
// 1: Set a picture to sow exile frame sequence animation // Array is usually an array of pictures // 2: Set the duration of the animation: 2.0 ; // 3: Set number of repetitions 1 ; ... ... // finally: Start animation
How to load images in an array
1:uiimage *img = [UIImage imagenamed:namepic];
//UIImage imagenamed This way is cached, if it is a second call, it is not taken from the file, but directly from the cache, that is, the memory will be more and more large
But take pictures directly from the memory, speed must be faster, performance is a bit higher
2: nsstring *fullpath = [[nsbundle mainbundle] pathforresource: Namepic OfType :Nil];
UIImage *newimg = [[UIImage alloc] initwithcontentsoffile: FullPath];
This is not cached, it is loaded with full path, but it will not be released automatically after the animation is finished, and only the next animation will be released; So generally we can manually release
// after the animation is finished, release the picture
[_tomimage performselector:@selector(animationimages) Withobject : nilafterdelay : self . Tomimage . animationduration ];
Summary: There are pros and cons in both ways, imagenamed performance is a bit higher, but the premise is that the image occupies a small amount of memory, and the graph is used in many places or frequently;
If, however, the picture storage space is big, the memory is unbearable, must use initwithcontentsoffile: FullPath.