Pulse like infinite scrolling of images loaded from Amazon Web Services S3
I would like to create an iphone application that displays three rows of infinite number of images that should be coming from AWS S3 and loaded on the fly while the user is scrolling to the right on each row. What I would like to do is have the top row small, middle row large and bottom row small. Cac开发者_Go百科hing and smart lazy loading for memory managment is critical.
I looked at Three20 but too complicated for such a simple task. Any idea of simple libraries or even better a native approach.
You should take a closer look at UIScrollView. Apple has created this class for the specific intentions of scrolling content. There are quite a few samples available from Apple, and they discussed this specific issue of content re-use and high quality scrolling at the most recent WWDC.
This basic strategy is to display content, and loop the scroll position in the same frame that the update thread would animate. This results in moving the content at the perfect moment to fool the user in to believing the content is 'infinite'.
Review: WWDC 2010: Session 104 - Designing Apps with Scroll Views
WWDC 2011 : Session 104 - Advanced Scroll View Techniques; Session 115 - Scrolling, Swiping, Dragging
While the concept is pretty easy to grasp, seeing how Apple accomplishes this task, and incorporating their best practices will result in the best code you can write for this platform.
Hi Gil Margolin,
For manage infinite horizontal scroll tableView is good choice instead of Scroll view you can easily manage lazy loading concepts on it.
There are many tutorial on that trick. in that trick main concept are, we have to take table as subview of main table`s Cell and make it transform.
Refer following links for this,
1) This one is good for clear trick of horizontal tableView Cell.
2) This one also good but little bit complicated.
After This you can manage Lazy loading concept in each cell tableView and get result what you want.
Best of Luck.
Here's native code for pulling imagers from S3. The first is the implementation of h of the custom S3 delegate. The second is the m file to get the objects from S3. The final method should be in the class of the table you want to display the pics in.
@protocol S3ObjectControllerDelegate
-(void)S3ControllerFinished:(NSString *)objectKey;
@end
@interface S3ObjectController :NSObject <AmazonServiceRequestDelegate>{
NSMutableData *responseData;
NSString *keyName;
AmazonS3Client *s3Client;
S3GetObjectRequest *s3GOR;
id <S3ObjectControllerDelegate> delegate;
}
-(void)s3GetRacerPictuers;
@property (nonatomic, strong) NSString *keyName;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) id <S3ObjectControllerDelegate> delegate; //was assign
@end
@implementation S3ObjectController
@synthesize keyName,image;
@synthesize delegate;
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Error %@",error);
}
-(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response
{
//NSLog(@"Response Key %@", response);
responseData = [[NSMutableData alloc]init];
}
-(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data
{
//NSLog(@"ObjectRequestKey = %@",request);
[responseData appendData:data];
}
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
UIImage *myImage = [[UIImage alloc]initWithData:responseData];
if(myImage == nil)
{
//NSLog(@"NO IMAGE");
image = [UIImage imageNamed:@"placeholder.png"];
responseData = nil;
}
else
{
//NSLog(@"image added");
image = myImage;
responseData = nil;
}
[[self delegate] S3ControllerFinished:keyName];
}
-(void)s3GetPictuers
{
// NSLog(@"Method Called");
s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
s3GOR = [[S3GetObjectRequest alloc]initWithKey:keyName withBucket:[Constants pictureBucket]];
s3GOR.delegate = self;
[s3Client getObject:s3GOR];
//NSLog(@"Method Finished");
}
@end
-(void)S3ControllerFinished:(NSString *)objectKey
{
S3ObjectController *newS3 = [[S3ObjectController alloc] init];
newS3 = [tempDictionary objectForKey:objectKey];
UIImage *tempImage = newS3.image;
[dictionaryOfImages setObject:tempImage forKey:objectKey];
[table reloadData];
}
精彩评论