Re: Cocoa-dev Digest, Vol 7, Issue 294
Re: Cocoa-dev Digest, Vol 7, Issue 294
- Subject: Re: Cocoa-dev Digest, Vol 7, Issue 294
- From: Shripada Hebbar <email@hidden>
- Date: Fri, 12 Mar 2010 10:32:07 +0530
- "x-copyrighted-material: http://www.robosoftin.com"
- Thread-topic: Cocoa-dev Digest, Vol 7, Issue 294
Hi Michael,
You can use a text filed inside a scrollview. And use CAKeyFrameAnimation on
the layer of the text field on its 'position' property.
The idea is something like this:
You need to compute the appropriate duration for the animation from the size
of the text you have. The duration needs to be proportional to the length of
string. And appropriately compute the target position (again this is decided
by the length of the string).
HTH
Regards
Shripada
On 12/03/10 7:45 AM, "email@hidden"
<email@hidden> wrote:
> From: "Michael A. Crawford" <email@hidden>
> Subject: Re: Need help with scrolling marquee
> To: email@hidden
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=us-ascii
>
> I played with the truncation property but to make that work you have to
> continually modify the length of the string. I want to write the string to
> the buffer once and then have CA scroll it for me at a constant speed I can
> set. This is where I'm looking for assistance.
>
> -Michael
>
> On Mar 11, 2010, at 4:58 PM, Eric E. Dolecki wrote:
>
>> 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
>>
>>
-----------------------------------------------
Robosoft Technologies - Come home to Technology
Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
_______________________________________________
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