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 6881897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:11:14+00:00 2026-05-27T05:11:14+00:00

I have 5 pictures inside an infinite scrollView. So in order to make that

  • 0

I have 5 pictures inside an infinite scrollView.

So in order to make that scrollView infinite/circular I positioned my images like this:

5 1 2 3 4 5 1
meaning: last picture first picture second picture…..last picture first picture

And in order for it to become infinite I have the following code:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if(self.scrollView.contentOffset.x == 0){

    [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];  
        }
    else if (self.scrollView.contentOffset.x == self.view.frame.size.width*(pathImages.count+1)) {         

    [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];    
    }
}

which means that when I’m at the last picture the contentOffset of the scrollView is set to go to the first picture-in this way I get an infinite scrollView.

  What I wanted next was for my scrollView to slide automatically-for this I set a timer which calls one method-onTimer:

- (void) onTimer{
    NSLog(@"flip pages");
    if(h < pathImages.count*self.view.frame.size.width)
    {
        h+= self.view.frame.size.width;

    }
    else
    {
        h=self.view.frame.size.width;
    }

    if(self.scrollView.contentOffset.x == 0){

        [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];  

    }

    if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)         

    {      

        [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];                         

    }

    else

    [UIView animateWithDuration:1 
                          delay:0 
                        options:UIViewAnimationOptionCurveEaseInOut 
                     animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); } 
                     completion:NULL];
}

This magic line:

[UIView animateWithDuration:1 
                              delay:0 
                            options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); } 
                         completion:NULL];

does the scoll automatically with animation.

Everything is great except this:

after I view the last picture I should set the offset of scroll view in order to get back to the first picture with animation.

Well if I do that:

if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)         
            {      
        [UIView animateWithDuration:1 
                                  delay:0 
                                options:UIViewAnimationOptionCurveEaseInOut 
                             animations:^{     [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];  } 
                             completion:NULL];                        

        }

after the last picture is viewed in order to get to the first picture…it loops through all the other pictures.

What I want is this:after I view the last picture to get me back to the first picture which should be loaded on screen using animation, but without viewing all the other pictures between them.Thanks

  • 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-05-27T05:11:14+00:00Added an answer on May 27, 2026 at 5:11 am

    If I see this correctly, the problem is, that you again use the animation to scroll the view back to zero position. I believe you need to modify the last bit of code you posted to something like this:

    if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)         
                {      
            [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];//no animation on returning
    [self onTimer];//even if this code is already inside method "onTimer"
            }
    

    Rather then what you are doing try using a scrollview that displays only 3 to 5 images at the time (if they are fullscreen). If you will have many images in your application, it will crash because of high memory consumption. Try playing with this test example that does nearly what you want:

    HEADER:

    #import <Foundation/Foundation.h>
    
    @interface IScrollView : UIScrollView <UIScrollViewDelegate> {
        NSMutableArray *imagePaths;
        UIImageView *imageViews[3];
        NSInteger currentImage;
        NSTimer *animationTimer;//weak link
    }
    @end
    

    SOURCE:

    #import "IScrollView.h"
    
    @implementation IScrollView
    - (UIImage *)imageFromResourcesWithName:(NSString *)name {
        UIImage *ret = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name]];
        return [ret autorelease];
    }
    - (id)initWithFrame:(CGRect)frame {
        if((self = [super initWithFrame:frame])) {
            imagePaths = [[NSMutableArray alloc] init];
            [imagePaths addObject:@"imag1.png"];
            [imagePaths addObject:@"imag2.png"];
            [imagePaths addObject:@"imag3.png"];
            [imagePaths addObject:@"imag4.png"];
            [imagePaths addObject:@"imag5.png"];
            imageViews[0] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*0, .0f, 320.0f, 480.0f)];
            imageViews[1] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*1, .0f, 320.0f, 480.0f)];
            imageViews[2] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*2, .0f, 320.0f, 480.0f)];
            [self addSubview:imageViews[0]];
            [self addSubview:imageViews[1]];
            [self addSubview:imageViews[2]];
            imageViews[0].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:0]];
            imageViews[1].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:1]];
            imageViews[2].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:2]];
            currentImage = 1;
            self.contentOffset = CGPointMake(320.0f*currentImage, .0f);
            self.contentSize = CGSizeMake(3.0f*320.0f, 480.0f);
            self.delegate = self;
            animationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(scrollFragment) userInfo:nil repeats:YES];
        }
        return self;
    }
    - (void)repositionIfNeeded {
        CGFloat offsetX = self.contentOffset.x;
        NSInteger iCount = [imagePaths count];
        if(offsetX > 320.0f*1.75f) {
            self.contentOffset = CGPointMake(offsetX-320.0f, .0f);
            imageViews[0].image = imageViews[1].image;
            imageViews[1].image = imageViews[2].image;
            NSInteger imageToLoad = currentImage+2;
            if(imageToLoad>iCount-1)
                imageToLoad -= iCount;
            imageViews[2].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]];
            currentImage++;
            if(currentImage>iCount-1)
                currentImage -= iCount;
        }
        else if(offsetX < 320.0f*.25f) {
            self.contentOffset = CGPointMake(offsetX+320.0f, .0f);
            imageViews[2].image = imageViews[1].image;
            imageViews[1].image = imageViews[0].image;
            NSInteger imageToLoad = currentImage-2;
            if(imageToLoad<0)
                imageToLoad += iCount;
            imageViews[0].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]];
            currentImage--;
            if(currentImage<0)
                currentImage += iCount;
        }
    }
    - (void)scrollFragment {
        self.contentOffset = CGPointMake(self.contentOffset.x+1.0, .0f);
        [self repositionIfNeeded];
    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        [self repositionIfNeeded];
    }
    - (void)dealloc {
        [imageViews[0] release];
        [imageViews[1] release];
        [imageViews[2] release];
        [imagePaths release];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have pictures that I would like to have expand across an entire page
I have this page that displays pictures in a div. I have jquery cycle
I have an activity that extends MapActivity, and inside onCreate() I have this code
I have the create inside the table/list that Grails provides. Here is a pictures
Inside a div, there is a picture that should have 10px margin in all
I have a pictures table that has the following columns: PICTURE_ID int IDENTITY(1000,1) NOT
I have a grid of profile pictures I am displaying in a window that
i have a jdialog with a jpanel inside it.I have jlabels(pictures) on the jpanel.How
I have a table that displays pictures in each td element. The page is
I have inside my app folder : images folder with images inside and I

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.