Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <pre><code>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" } </code></pre> <p>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:</p> <p>HEADER:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface IScrollView : UIScrollView &lt;UIScrollViewDelegate&gt; { NSMutableArray *imagePaths; UIImageView *imageViews[3]; NSInteger currentImage; NSTimer *animationTimer;//weak link } @end </code></pre> <p>SOURCE: </p> <pre><code>#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 &gt; 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&gt;iCount-1) imageToLoad -= iCount; imageViews[2].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]]; currentImage++; if(currentImage&gt;iCount-1) currentImage -= iCount; } else if(offsetX &lt; 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&lt;0) imageToLoad += iCount; imageViews[0].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]]; currentImage--; if(currentImage&lt;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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload