でギャラリーを作成しUICollectionView
、plist ファイルから一連の画像を読み込みます。ユーザーが各セルに触れると、フルスクリーンの画像が読み込まれます (iPhone の写真アプリケーションと同じ)。全画面表示にする他の画像をスクロールして表示することはできません。ここに私のコードがあります:
次に 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];
}
}
編集:(解決策)
-(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];
}