1

我有一个 UIScrollView。我想实现一个无限的左侧滚动效果。这怎么可能?

- (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);
    }
}

我曾尝试将 contentoffset 设置为 SCrl_Wheel.contentOffset = CGPointMake(0, 0);

但它实际上并没有设置contentoffset.x=0;

这正在制作:-[SCrl_Wheel setContentOffset:CGPointMake(0,0) animated:YES];我的循环是无限循环。

4

3 回答 3

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);
于 2012-10-13T10:42:22.310 回答
1

将此添加setContentSize:到您的代码中。

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

现在它会像你想要的那样滚动,为什么你要添加你的 y = 0 ?那么高度UIScrollView是 0....

编辑:

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

添加此代码 ull b 让双方滚动你的方式:) 我测试了它......

于 2012-10-13T09:34:35.993 回答
0

这是我用于向左滚动的代码:

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];
于 2012-10-13T10:24:59.827 回答