1

I have a UIScrollView. I want to implement an infinite left side-scrolling effect. How can this be possible?

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat pageWidth = scrollView.frame.size.width/7;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    Lbl_Rate.text=[NSString stringWithFormat:@"   pagenumber==>%d",page ];  
    int p=page%10;
    if(p==0){ 
        page=1;
        SCrl_Wheel.contentOffset = CGPointMake(0, 0);
    }
}

I had trid to set contentoffset by SCrl_Wheel.contentOffset = CGPointMake(0, 0);

But it is not actually setting contentoffset.x=0;

And this is making :-[SCrl_Wheel setContentOffset:CGPointMake(0,0) animated:YES]; my loop as infinite loop.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ios developer
  • 3,363
  • 3
  • 51
  • 111
  • What do u mean by left side ?? – IronManGill Oct 13 '12 at 09:15
  • @Gill I want to implment the horizontal scrolling.I had give [SCrl_Wheel setContentSize:CGSizeMake(100000,0)]; It allow me to scroll on right side.But not allowing me to scroll on left side – ios developer Oct 13 '12 at 09:28
  • You can use the `contentOffset` property of the `UIScrollView` to achieve this. For sample codes and details check these links: [Link 1](http://mobiledevelopertips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html) [Link 2](https://stackoverflow.com/questions/3430267/uiscrollview-infinite-scrolling) [Link 3](https://stackoverflow.com/questions/5693097/infinite-uiscrollview-in-both-direction/8319984#8319984) [Link 3](https://stackoverflow.com/questions/1845789/how-to-create-a-uiscrollview-of-infinite-scrolling) – Midhun MP Oct 13 '12 at 09:18

3 Answers3

1

Add this setContentSize: to your code.

[SCrl_Wheel setContentSize:CGSizeMake(-100000,50)];

Now it would scroll like the way you want to and why hav u added your y = 0 ?? then the height of the UIScrollView would be 0....

EDIT:

   [SCrl_Wheel setContentOffset:CGPointMake(1000, 0.0)];

Add this code ull b getting both sides scrolling ur way :) I tested it ...

IronManGill
  • 7,222
  • 2
  • 31
  • 52
  • Thanks for the quick reply.But by making [SCrl_Wheel setContentSize:CGSizeMake(-100000,50)]; It stops the scrolling behavinour – ios developer Oct 13 '12 at 09:38
1

To add Left Side scrolling effect, you can create a scrollview with very large width and then set its initial contentOffset to midpoint of contentwidth of scrollview :

scrollView.contentSize = CGSizeMake(100000, 60);
scrollView.contentOffset = CGPointMake(scrollView.contentSize.width/2, 0);
Bhupendra
  • 2,525
  • 18
  • 20
0

This is the code I used for scrolling left:

HorizontalScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,50,yourView.frame.size.width,tbv.frame.size.height)];
        [HorizontalScroll setContentSize:CGSizeMake(930,340)];
        [HorizontalScroll setBackgroundColor:[UIColor redColor]]; // color is set just to know where the scroll view is , remove this line afterwards.
        [self.view addSubview:HorizontalScroll];
        [HorizontalScroll addSubview:yourView];
Deepjyoti Roy
  • 482
  • 4
  • 15