I have got all images of iphone using AssetsLibrary.I am passing UIImage object in imageview and display images in scrollview. There are more than 200 images in iphone and i have to display all images in scrollview vertically without use of paging.This takes lots of time to display images and it has also memory issues. Is there any code for lazy loading of iphone images in scrollview
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
I've been working on this recently and have checked out loads of example code on the web. None of it really did lazy loading (despite the claim) or had much more complexity (needless bells and whistles) than I was willing to put up with. The Apple WWDC videos for PhotoPicker appear to show lazy loading but seem more focused on tiling of pre-sliced up images, so not much help there.
What I've ended up doing is to load all the
aspectThumbnails
at once, since they are small and don't take up that much memory and then load thefullScreenImage
representation on demand fromscrollViewDidEndDecelerating
and reload theaspectThumbnail
for the imageView going off-screen. The effect is very fluid and visually, the image comes in a little rough and then quickly (through background loading) is replaced with the higher resolution image.It can probably use more refinement - perhaps loading full resolution images for the currentPage +1 & -1. I haven't got around to that as yet. Also, I'm not entirely sure if my use of blocks in optimal – but not getting an errors.
I call this from a Segue and set the
assetsArray
(NSArray of ALAssets) from within theprepareForSegue:
method on my root viewController.//ScrollViewController.m
You can use GCD block and grand central dispatch. in your .h file declare it
Create an NSmutableDictionary
Use below Code to Show image.
You should only have loaded the images on the current page plus one or two in either direction. Only load images when you need them, keeping a limited buffer, and remove images after they have left the buffer. For example, if images 3 and 4 are on screen, images 1,2,5, and 6 should be loaded. When the user scrolls such that images 5 and 6 are on screen, it will keep images 3 and 4 loaded, will remove 1 and 2 from its memory, and will load 7 and 8 to make a new buffer.
There are many tutorial available for this.
Let me point some of them:
How To Use UIScrollView to Scroll and Zoom Content
Scroll Lazy Image Load for iOS
If you dont have problem in using someone's code
DMLazyScrollView : Lazy Loading UIScrollView (with infinite page scrolling)