I have created a gallery with UICollectionView , and load a set of images from a plist file , when user touches each cell , a fullscreen image will be loaded (same as iPhone’s Photos application) , so I have faced with a problem which is when photo will be fullscreen I can not scroll and view other images , here is my codes :
then in PhotosViewerController :
-(void) creatContentWithNumerOfPage: (NSInteger) numberOfPage andCurrentPage: (NSInteger) currentPage andImageArray:(NSArray *)imageArray {
self.pageControl.numberOfPages = numberOfPage;
self.pageControl.currentPage = currentPage;
[pageScrollView setContentSize:CGSizeMake(self.view.frame.size.width * pageControl.numberOfPages, self.view.frame.size.height)];
pageScrollView.delegate = self;
[self.view addSubview: pageScrollView];
NSMutableArray *mArray = [[NSMutableArray alloc] initWithCapacity:thumbnailViewController.imageArray.count];
for (int i = 0; i <= thumbnailViewController.imageArray.count; i++)
{
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Photos" ofType:@"plist"]];
imageArray = [picturesDictionary objectForKey:@"PhotosArray"];
fullScreen = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[imageArray objectAtIndex:currentPage]]];
[fullScreen setContentMode:UIViewContentModeScaleAspectFit];
fullScreen.frame = self.view.frame;
[mArray addObject:fullScreen];
[pageScrollView addSubview:fullScreen];
}
}
EDITED : (solution)
-(void) creatContentWithImages:(NSArray*)imageArray andCurrentPage:(NSInteger)currentPage{
self.pageControl.numberOfPages = imageArray.count;
self.pageControl.currentPage = currentPage;
[self.pageScrollView setContentSize:CGSizeMake(self.pageScrollView.frame.size.width * imageArray.count, self.pageScrollView.frame.size.height)];
for (int i = 0; i < imageArray.count; i++)
{
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Photos" ofType:@"plist"]];
imageArray = [picturesDictionary objectForKey:@"PhotosArray"];
fullScreen = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[imageArray objectAtIndex:i]]];
[fullScreen setContentMode:UIViewContentModeScaleAspectFit];
fullScreen.frame = CGRectMake(i*self.pageScrollView.frame.size.width, 0, self.pageScrollView.frame.size.width, self.pageScrollView.frame.size.height);
[self.pageScrollView addSubview:fullScreen];
}
[self scrollToPage:currentPage animated:NO];
}
Your code have a lot of issues, for example
you call
creatContentWithImagesbeforeviewDidLoadmethod and at thispoint we can’t expect real values of
self.view.frameorself.pageScrollView.frame, you have to call it in/afterviewDidLoad.Maybe like this:
in cycle you always use
currentPageinstead ofiivarimageArrayintocreatContentWithNumerOfPagemethod butfor some reason this array is being overriden here with new data (I
suppose with the same data)
[self.view addSubview:– is UIScrollView created programmatically? But in which place it happens?pageScrollView]
not UIView, if your scroll size will be different from UIView then
design will be broken as well.
I’ve changed it and improved some things, so let look at this (I posted all whole PhotosViewerController.m file)
If you still have any questions then let me know, and I try help you.