Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8925111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:36:37+00:00 2026-06-15T07:36:37+00:00

I have created a gallery with UICollectionView , and load a set of images

  • 0

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];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:36:38+00:00Added an answer on June 15, 2026 at 7:36 am

    Your code have a lot of issues, for example

    • you call creatContentWithImages before viewDidLoad method and at this
      point we can’t expect real values of self.view.frame or
      self.pageScrollView.frame, you have to call it in/after viewDidLoad.
      Maybe like this:

      [self presentViewController:photosViewController animated:YES completion:^{
          [photoViewController creatContentWithImages:images andCurrentPage:row];
      }];
      
    • in cycle you always use currentPage instead of i ivar

    • you send imageArray into creatContentWithNumerOfPage method but
      for some reason this array is being overriden here with new data (I
      suppose with the same data)
    • it’s also unclear why you perform [self.view addSubview:
      pageScrollView]
      – is UIScrollView created programmatically? But in which place it happens?
    • when you operate with frames then you should use UIScrollView frame,
      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)

    #import "PhotosViewerController.h"
    @implementation PhotosViewerController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    -(void) creatContentWithImages:(NSArray*)imageArray andCurrentPage:(NSInteger)currentPage{
    // I create UIScrollView programmatically, if you want to use xib then just remove lines with RM comment. 
    // There are two views in xib hierarchy - UIScrollView downward and UIPageView above
    
        self.pageScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; //RM
        self.pageScrollView.pagingEnabled = YES; //RM
    
        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)];
    
        self.pageScrollView.delegate = self;//RM
        [self.view insertSubview:self.pageScrollView atIndex:0]; //RM
    
        for (int i = 0; i < imageArray.count; i++) //not <=, just <
        {
            UIImage *img = [imageArray objectAtIndex:i];// not sure whether imageArray contains UIImage's or NSString, so if here NSString the create UIImage in appropriate manner. I've tested it with UIImage's 
            UIImageView *fullScreen = [[UIImageView alloc] initWithImage:img];
            [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]; // scroll to corresponding page
    }
    
    - (void)scrollViewDidScroll: (UIScrollView *) sView
    {
        CGFloat offset = self.pageScrollView.contentOffset.x;
        CGFloat pageSize = self.pageScrollView.frame.size.width;
    
        int page = floor((offset + (pageSize/2)) / pageSize);
        self.pageControl.currentPage = page;
    }
    
    - (IBAction)changeThePage:(id)sender
    {
        NSLog(@"Change");
        [self scrollToPage:self.pageControl.currentPage animated:YES];
    }
    
    - (void)scrollToPage:(NSInteger)page animated:(BOOL)animated{
        CGRect pageRect = CGRectMake(page * self.pageScrollView.frame.size.width, 0, self.pageScrollView.frame.size.width, self.pageScrollView.frame.size.height);    
        [self.pageScrollView scrollRectToVisible: pageRect animated: animated];
    
        [self.pageControl setCurrentPage:page];
    }
    @end
    

    If you still have any questions then let me know, and I try help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a XML image gallery, which displays text in between each slide.
I've created small app that works with images from gallery or camera. It all
i have created a gallery script, which first loads images to be shown http://bit.ly/9aQdr3
I have created a gallery, and it displays a lot of images in a
I have created this slider using motiongallery.js (CMotion Image Gallery) from Dynamic Drive. I'm
I have created a class which extends Gallery. There is no onCreate() method in
I have an image gallery that I created by reading the contents inside a
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
As of right now, in my app I have created a rudimentary gallery app
i have an app with a gallery of images and i want that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.