views:

37

answers:

1

Hi all,

I have a looping scrollView but I want the user to be able to speed up the scrolling by interacting with the scrollView (ie scrolling with their finger) if they choose. Do I have to do extra work to acheive this as at the moment the animated scrolling takes priority over the users interaction and slows the scroll down dramatically. Has anyone done something similar? As an example Im looking to acheive as similar affect to that used in the about screen on the angry birds game?

Many thanks

Here us the code for basice animation of the scroll view

[UIView beginAnimations:@"scroll " context:nil];
[UIView setAnimationDuration:15];

[scrollView setContentOffset:CGPointMake(0, 600) animated:NO];
[UIView commitAnimations];

As soon as the user tries to scroll, the scrollView slightly scrolls (it moves very slightly), then stops the user scroll action and continues with the animated scroll? So the overall appearance is as follows :

1.animating scroll 2. user tries to scroll and animation appears to stick 3. when user ends scroll animation continues Any thoughts?

Many thanks again.

A: 

If I understand what you're trying to say, you want a continuous, slow scroll (600px per 15 seconds) which can be overruled by the user.

If this is what you want, I'd take a different approach than this one. The animation you're firing, when started, will probably just do what it's told, while the user is interacting as well, which will all get very messy.

Create an NSTimer which takes care of the slow scrolling motion, one pixel at a time. Then the user can still interact freely.

something like:

...
NSTimer *slow = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollALittle:) userInfo:nil repeats:YES];
...
// maybe, somewhere:
[slow invalidate];

-(void)scrollALittle:(NSTimer*)theTimer
{
    CGPoint offset = scrollview.contentOffset;
    offset.y+=4; // 10 times 4 pix a second makes 600px/15 seconds.
    // add check on max y?

    // these checks are deliberately placed as close as possible to the contentOffset assignment
    if ( scrollview.tracking ) return;
    if ( scrollview.dragging ) return;
    if ( scrollview.zooming ) return;
    if ( scrollview.decelerating ) return;

    scrollview.contentOffset = offset;
}

of course you can do a lot of things here, but this may be a starting point.

mvds
Thank you this worked well. The only slight thing was I had to change the time interval to be slightly more frequent as the result was slightly jerky at 1st, other than that. Great answer many thanks.Jules
Jules