Re: Need help with scrolling marquee
Re: Need help with scrolling marquee
- Subject: Re: Need help with scrolling marquee
- From: "Eric E. Dolecki" <email@hidden>
- Date: Thu, 11 Mar 2010 16:58:02 -0500
Isn't there a truncation property that handles this for a UILabel?
On Thu, Mar 11, 2010 at 4:53 PM, Graham Cox <email@hidden> wrote:
>
> On 12/03/2010, at 5:23 AM, Michael A. Crawford wrote:
>
> > - (void)timerFireMethod:(NSTimer*)theTimer
> > {
> > #if 0
> > // Here I was using a periodic timer to animate the scroll. I noticed
> that
> > // the animation wasn't smooth and then remembered that CA is supposed
> to do
> > // the animating for me. So, I switched to trying the code below but
> that
> > // doesn't work either. I'm really just grasping at straws here.
> > static CGPoint origin = {0.0f, 0.0f};
> > origin.x += 5.0f;
> > [scrollLayer scrollToPoint:origin];
> > #else
>
>
> Hi Michael,
>
> This is a classic "naive" mistake. You're incrementing the position by a
> fixed amount each time the timer fires. Problem is, you can't guarantee that
> the timer will fire exactly at the time it should, so your scrolling speed
> is at the mercy of how busy things are, so will speed up and slow down.
>
> Recall that speed is distance/time, so if you want a constant speed, you
> have to work out how much distance the thing should have moved in the actual
> time interval you got.
>
> Roughly (typed into mail):
>
> - (void) timerFireMethod:(NSTimer*) theTimer
> {
> NSTimeInterval elapsedTime = [NSDate timeIntervalSinceReferenceDate] -
> m_startTime; // m_startTime ivar set when the animation began
> CGFloat distance = m_speed * elapsedTime; // m_speed is the scrolling
> speed in points per second
>
> [thing setPosition:distance];
> }
>
> With this approach, the exact timing intervals don't matter - the position
> will be correct. If things get busy what will happen is that the jumps
> between positions will get a bit larger.
>
> That said, Core Animation might do the job better, but I just wanted to
> point out what the problem was with your original approach.
>
> --Graham
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
http://ericd.net
Interactive design and development
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden