On 07/01/2010, at 2:23 PM, Chunk 1978 wrote:
> unfortunately i'm developing for iPhone OS (which i should have stated
> earlier) so NSAnimation doesn't seem to be an option :-/
So just use NSTimer, within or without a wrapper object of your own devise.
Here's the basics of the code I used, which implements a generic fade method.
This is called for a number of different tasks, such as fading in, fading out
and ducking the track. Warning: this is an old project, and I think I would do
things slightly differently now, but the basic principle of using a repeating
timer remains the way to go, IMO.
- (void) fadeFromLevel:(float) l1 toLevel:(float) l2
inTime:(NSTimeInterval) time
{
// performs a linear fade from l1 to l2 over the time interval <time>.
if ( _fader == nil )
{
DJFadeInfo* fi = [[DJFadeInfo alloc] initWithLevel1:l1
level2:l2 time:time];
_fader = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0
target:self
selector:@selector(fadeCallback:)
userInfo:fi
repeats:YES];
_fadeStartTime = [[NSDate date] retain];
}
}
- (void) fadeCallback:(NSTimer*) timer
{
//NSLog(@"fade target = %@", [self name]);
DJFadeInfo* fi = [timer userInfo];
NSTimeInterval t = [[NSDate date]
timeIntervalSinceDate:_fadeStartTime];
float vol = [fi level1] + ([fi delta] * ( t / [fi time]));
if ( t > [fi time])
{
[_fader invalidate];
_fader = nil;
[_fadeStartTime release];
_fadeStartTime = nil;
[self setMainLevel:[fi level2]];
[fi release];
}
else
{
[self setMainLevel:vol];
}
}
--Graham
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]