this article reprinted to http://mobile.51cto.com/iphone-413267.htmshare a private album today, read load, swipe through a large number of image solutions, I would like to emphasize that the concept of programming is not related to platform constraints. I would like to say in detail, after clicking on any small thumbnail in the thumbnail interface, into the high-definition Full Screen browsing interface of this short 1 seconds (and the next few seconds), what happened.
AD:2014WOT Global Software Technology Summit Beijing Station course video release
Share a private album today, read load, swipe through a large number of image solutions, I would like to emphasize that the concept of programming is not related to platform constraints.
I would like to say in detail, after clicking on any small thumbnail in the thumbnail interface, into the high-definition Full Screen browsing interface of this short 1 seconds (and the next few seconds), what happened.
General thinking Process
When you click on any small map,
1. First make ScrollView frame: size 2 ScrollView, small for gesture Zoom single picture, large horizontal load all photos sequentially
2. After making the ScrollView frame, load the photo
3. All ready jump page presented to the user selected large map
Loading the picture This step, if the photo album within 10 photos, then there is no technical challenge, but if it is 300 photos? A direct crash? or let the user wait for the load? Time-intensive task, this step needs to be split and optimized.
ScrollView Framework needs to understand the next API, and then move the brain, here is a little trick, a lot of people ask me how the black edge between photos and photos how to achieve, hehe, put the code:
- #define PADDING 20
- -(Nsinteger) Loadphotos
- {
- Photo before cleaning
- For (UIView *v in [_scrollview Subviews]) {
- [v Removefromsuperview];
- }
- Workingframe = [[UIScreen mainscreen]bounds];
- workingframe.origin.x = PADDING;
- for (int i = 0; i < int_total; i++) {
- CGRect frame = workingframe;
- Wqphoto *photoview = [[Wqphoto alloc] initwithframe:frame];
- [PhotoView setscroller:self];
- [PhotoView setindex:i];
- Wqalbumphoto *photo = [Albumobject._photos objectatindex:i];
- [Photo Cleanthumbnail];
- if (i = = int_current) {
- Loading the original
- [PhotoView SetImage:photo.oriImage];
- [PhotoView Setisload:yes];
- }else if (int_current-10 < i && i < Int_current + 10) {
- Load thumbnails near and around
- [PhotoView SetImage:photo.thumbnail4view];
- }
- [_scrollview Addsubview:photoview];
- workingframe.origin.x = workingframe.origin.x + 2 * PADDING
- + workingFrame.size.width;
- }
- Implement scrollable
- [_scrollview Setcontentsize:cgsizemake (Workingframe.origin.x, WORKINGFRAME.SIZE.HEIGHT/2)];
- [_scrollview setcontentoffset:cgpointmake (int_current, 0)];
- Load the remaining thumbnails
- Loadthread = [[Nsthread alloc]initwithtarget:self selector: @selector (loadimages) Object:nil];
- return 0;
- }
Using low-resolution graphs
Think carefully, in fact, there is no need to load all the pictures of the high-definition original, in advance to save each map supporting the low-resolution diagram, with space for time.
First load all the pictures of the low-resolution graph, when the user browses to a picture, the real-time loading of the original size HD uncensored large image. Process optimizations are:
multithreaded tasks
Even so, when the number of photos reached a certain amount, the time required to consume is not a millisecond level, experience can not be satisfied, page jumps will still appear in the phenomenon of Dayton.
Then consider using multithreading to further split the task, perform a jump and then perform the process of loading the low-resolution graph in the background.
Optimize your quick-flip experience
With this split, you can immediately jump and experience satisfaction. However, when browsing, when the user quickly swipe left and right, the chance of a black screen is very high, because the load of the low-resolution graph task may still be a lot of IO operation, not in time to keep up. In order to improve it, to load the low-resolution diagram of the steps to decompose again, excellence.
Within the allowable range of page jump time, load the high-definition artwork of the user-selected image, and load as many as possible a low-resolution picture of the neighboring pictures.
How do I load the rest of the low-resolution graphs?
To the user click on the selected map to the center of the load, the direct thinking should be two threads a left and right load, and then think about the loading can actually be a cycle, free of those who are the cost of the thread.
- -(BOOL) loadimages
- {
- for (int i = int_current-10, j = int_current + ten;!) (i < 0 && Int_total-1 < j);-I, ++j) {
- if (! ( I < 0)) {
- Wqphoto *photo_pre = [_scrollview.subviews objectatindex:i];
- Wqalbumphoto *photopre = [Albumobject._photos objectatindex:i];
- [Photo_pre SetImage:photoPre.thumbnail4view];
- }
- if (! ( Int_total-1 < J)) {
- Wqphoto *photo_next = [_scrollview.subviews objectatindex:j];
- Wqalbumphoto *photonext = [Albumobject._photos objectatindex:j];
- [Photo_next SetImage:photoNext.thumbnail4view];
- }
- }
- return YES;
- }
And finally a chop.
Try to reduce memory consumption. Because the original image is much larger than the low-resolution graph, when the user browses from one image to another, the current picture is loaded into a large, high-definition image of the original size, and the original is replaced with a low-resolution graph. Although the number of read and write increased, but memory does save a lot.
To tell you the truth, there are a lot of albums on the market, the app, will have a lag in the jumping feeling, hehe ...
iOS development load, swipe to scroll through a large number of image optimization solutions