1
votes

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.

3
What do u mean by left side ?? - IronManGill
You can use the contentOffset property of the UIScrollView to achieve this. For sample codes and details check these links: Link 1 Link 2 Link 3 Link 3 - Midhun MP
@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

3 Answers

1
votes

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 ...

1
votes

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);
0
votes

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