0

Hi i am implementing application with uiscrollview. in uiscroll view i have imageview to load imaged. i am able to scroll and move forward like 1,2,3,4,...10, but when i am in 1 st image i want to scroll in backward direction also like 1 to 10,9,8... can any one help me what i need to add in my code thank you

here is my sample code what i have implemented

- (void)loadScrollViewWithPage:(int)page {

  if(page < 0 ||  (page >= [flashCardArry count]))
      return;
    FlashcardViewController *flashViewCntlObj = [flashCardViewController objectAtIndex:page%3];
  //if (nil == flashViewCntlObj.view.superview)
  {

    CGRect frame = cardsScrollView.frame;
    frame.origin.x = frame.size.width * page;


    NSLog(@"%f",frame.origin.x);
    frame.origin.y = 0;
    flashViewCntlObj.view.frame = frame;
    [cardsScrollView addSubview:flashViewCntlObj.view];

    [flashViewCntlObj setflashcardObj:[flashCardArry objectAtIndex:page]];
  }

}


- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    //iscardAttended = NO;

    CGFloat pageWidth = cardsScrollView.frame.size.width;
    NSUInteger page = floor((self.cardsScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    if(page + 1 == [flashCardArry count]){
        for (NSUInteger i = 0; i < [flashCardArry count]; ++i) {
            int nElements = [flashCardArry count] - i;
            int n = (arc4random() % nElements) + i;
            [flashCardArry exchangeObjectAtIndex:i withObjectAtIndex:n];
        }
        [self.cardsScrollView scrollRectToVisible:CGRectMake(self.cardsScrollView.frame.size.width * 0 , 0, self.cardsScrollView.frame.size.width, self.cardsScrollView.frame.size.height)  animated:NO];
    }
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

  CGFloat pageWidth = cardsScrollView.frame.size.width;

  NSUInteger page = floor((self.cardsScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

      DBWrapper *dbWrapper = [DBWrapper sharedWrapper];

    [self loadScrollViewWithPage:page - 1];
     [self loadScrollViewWithPage:page];
     [self loadScrollViewWithPage:page + 1];
}
Boosa Ramesh
  • 379
  • 3
  • 19
  • looks like infinite scroll view .. see this http://stackoverflow.com/questions/11862653/how-to-make-infinite-scroll-view-in-iphone – Shankar BS Mar 28 '14 at 07:19
  • There's an apple sample project for this: https://developer.apple.com/library/ios/samplecode/StreetScroller/Listings/StreetScroller_InfiniteScrollView_m.html – CW0007007 Mar 28 '14 at 08:31

1 Answers1

0

Watch the Advanced ScrollView Tecniques in WWDC 2011 https://developer.apple.com/videos/wwdc/2011/

Fry
  • 6,235
  • 8
  • 54
  • 93