开发者

Help scrolling through a UIScrollView

开发者 https://www.devze.com 2023-02-10 20:07 出处:网络
I am placing array of images in a scrollview. I need to autoscroll the scrollview. I am using the timer and increasing the position of scrollview.

I am placing array of images in a scrollview.

I need to autoscroll the scrollview. I am using the timer and increasing the position of scrollview.

My code looks like this.

- (void)autoscrollmethod {
    Timer = [NSTi开发者_开发问答mer scheduledTimerWithTimeInterval:7.5 target:self selector:@selector(moveRect) userInfo:nil repeats:YES];
}
- (void)moveRect {
    NSLog(@">>>>>>>> %d",i);
    [gallery scrollRectToVisible:CGRectMake(i,0,100,100) animated:NO]; 
    if (i==(arraycount+1)*100) {
        [gallery scrollRectToVisible:CGRectMake(0,0,100,100) animated:NO];
        i=200;
    }
    else {
        i=i+100;
    }
} 

It working fine,but I have a problem.

I am scrolling the view to position 800, but scrollRectToVisible:CGRectMake is at 600,then scrollview is not getting back to 600 position,and not autoscroll up to 800.

After 800 it will automatically scrolls normally.

How can I fix this?


Generally speaking, you should use the contentOffset property of the UIScrollView instead of manually using your own increment variable. Contentoffset changes depending on your scrolling and automatically changes itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消