views:

184

answers:

2

Hi,

I used the setContentOffset method to scroll to a particular point automatically without user interaction.

[menuScrollView setContentOffset:CGPointMake(600.0,0) animated:YES]

but when i try to call the same method in a looping fashion inorder to slow down the speed of scrolling the scrolling never happens

for (int i = 1; i<=30; i++) {
        [menuScrollView setContentOffset:CGPointMake(600.0-i*10,0.0) animated:YES];
        NSLog(@"%f",600.0-i*10);        
    }

During the above piece of code the scrolling of UIScrollview happens only once (1st iteration( and it does not scroll for remaining 29 interations. What is the problem here ?

+2  A: 

I think that when it's in a loop like this, the UI won't be updated.

Try using an NSTimer instead of putting it in a tight loop like this.

scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(scrollView) userInfo:nil repeats:YES];

- (void) scrollView {
    CGFloat currentOffset = menuScrollView.contentOffset.x;
    CGFloat newOffset = currentOffset - 10;
    [menuScrollView setContentOffset:CGPointMake(newOffset,0.0) animated:YES];
}

Note: this is from the top of my head, so I don't guarantee that it will work.

Rengers
thanks it worked. But is there any other way to move to make the scroll similar to marquee in HTML ?. this one is slow but i can feel that moving is not in a consistent speed. I tried this by decreasing the time interval but it is not looking fine, it is looking like a kind of shaking in both the direction. How to fix this up ? or is ther any other way to solve the marquee problem ?
thndrkiss
A: 

bump.. I have the same issue..Anyone pleaseee

Mahadevan S