I am stuck in a weird problem,tried to find out solution from all possible sources but no luck yet.
My requirement is something similar to photoviewer app of iphone,but there is more to that like uploading image,downloading etc .So technically what i am doing is creating a main scrollview,which has content size equal to all the selected image size * image width .I have small view inside that is also equal to no. of images selected from picker .The view contains a small scrollview,and an image view which allows user to zoom,pinch etc and the main scroll view has gesture listner which allows to swipe. To access the images i am storing Asset URL and get the image when user swipes left or right .At any point in time I am keeping only 1 image is memory i.e if user swipe to 2nd photo i delete the 1st photo from main scrollview .
But still i am facing memory issues on iPod if i selected 125 photos and swipe multiple times to end and come back .
Sample Code.:-
***//InnerScrollView is the class which contains view with scroll and imageview
//The values of initial and final counter will always be a diffrence of 1 so it creates only one object**
for(int j=initialCounter;j<finalCounter;j++) {
InnerScrollView *innerScrollViewObj=[[InnerScrollView alloc] initWithFrame:CGRectMake(320*j, 0, 320, 480)
url:[selectedImageList objectAtIndex:j] tag:self.initialImageViewCounter];
innerScrollViewObj.delegate=self;
[mainScrollView addSubview:innerScrollViewObj];
[innerScrollViewObj release];
innerScrollViewObj=nil;
}
**//This is main scrollview which gets created once**
mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0 , 320, 480)];
mainScrollView.pagingEnabled = YES;
// mainScrollView.delegate=self;
mainScrollView.showsHorizontalScrollIndicator = NO;
mainScrollView.showsVerticalScrollIndicator = NO;
mainScrollView.maximumZoomScale = 4.0;
mainScrollView.minimumZoomScale = 1.0;
mainScrollView.backgroundColor=[UIColor blackColor];
[mainScrollView setCanCancelContentTouches:NO];
mainScrollView.clipsToBounds = YES;
mainScrollView.scrollEnabled = FALSE;
mainScrollView.contentSize = CGSizeMake(320*[selectedImageList count], mainScrollView.bounds.size.height);
[self.view addSubview:mainScrollView];
//THis is the method which gets called when i swipe left and the previous images gets deleted
-(void)deleteScrollViewFormMainView:(NSNumber*)indexToDelete{
@try{
NSLog(@"ScrollView to be deleted %@",[[mainScrollView subviews] objectAtIndex:0]);
[[[mainScrollView subviews] objectAtIndex:0] removeFromSuperview];
}
@catch (NSException *e) {
NSLog(@"ScrollView view exception %@",[e description]);
}
}
- (id)initWithFrame:(CGRect)frame url :(ALAsset*) imageUrl tag:(int)tag
{
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled=YES;
// self.tag=tag;
UIImage *image = [UIImage imageWithCGImage:[[imageUrl defaultRepresentation] fullResolutionImage ]];
UIImageView* imageview = [[UIImageView alloc] initWithImage:image];
imageview.tag = VIEW_FOR_ZOOM_TAG;
imageview.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
imageview.backgroundColor=[UIColor clearColor];
imageview.contentMode=UIViewContentModeScaleAspectFit;
UIScrollView* pageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
NSLog(@"Page scrollview is %@",pageScrollView);
pageScrollView.tag=tag;
pageScrollView.minimumZoomScale = 0.4f;
pageScrollView.maximumZoomScale = 2.0f;
pageScrollView.zoomScale = 1.0f;
pageScrollView.backgroundColor=[UIColor clearColor];
pageScrollView.delegate = self;
pageScrollView.showsHorizontalScrollIndicator = NO;
pageScrollView.showsVerticalScrollIndicator = NO;
[pageScrollView setCanCancelContentTouches:NO];
[self addSubview:pageScrollView];
[pageScrollView addSubview:imageview];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap)];
singleTap.numberOfTapsRequired=1;
singleTap.delegate=self;
[self addGestureRecognizer:singleTap];
singleTap=nil;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap)];
doubleTap.numberOfTapsRequired=2;
doubleTap.delegate=self;
[self addGestureRecognizer:doubleTap];
singleTap=nil;
doubleTap=nil;
imageview=nil;
pageScrollView=nil;
}
return self;
}
Should i make InnerImageView class as singelton class?Will this help,because i think the memory issues can be because multiple objects are getting created(though i am release it properly).
Please help guys.!! Thanks in advance.