Skip to content

Commit

Permalink
Customizable animation duration
Browse files Browse the repository at this point in the history
Added two properties to customize the animation speed. If not set, the
previous default values are used (0.2,0.35).
  • Loading branch information
erndev authored and erndev committed Dec 6, 2011
1 parent 93d7e1d commit bce123d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Sample/Sample/ANSegmentedControl/ANSegmentedControl.m
Expand Up @@ -53,15 +53,27 @@ - (void)animateTo:(int)x;
- (void)setPosition:(NSNumber *)x;
- (void)offsetLocationByX:(float)x;
- (void)drawCenteredImage:(NSImage*)image inFrame:(NSRect)frame imageFraction:(float)imageFraction;
- (void)setDefaultDurations;
@end

@implementation ANSegmentedControl
@synthesize fastAnimationDuration=_fastAnimationDuration;
@synthesize slowAnimationDuration=_slowAnimationDuration;


+ (Class)cellClass
{
return [ANSegmentedCell class];
}

- (id) initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if( self )
{
[self setDefaultDurations];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (![aDecoder isKindOfClass:[NSKeyedUnarchiver class]])
Expand All @@ -74,6 +86,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder
[unarchiver setClass:newClass forClassName:NSStringFromClass(oldClass)];
self = [super initWithCoder:aDecoder];
[unarchiver setClass:oldClass forClassName:NSStringFromClass(oldClass)];

[self setDefaultDurations];

return self;
}
Expand Down Expand Up @@ -227,10 +241,10 @@ - (void)animateTo:(int)x
ANKnobAnimation *a = [[ANKnobAnimation alloc] initWithStart:location.x end:x];
[a setDelegate:self];
if (location.x == 0 || location.x == maxX){
[a setDuration:0.20];
[a setDuration:_fastAnimationDuration];
[a setAnimationCurve:NSAnimationEaseInOut];
} else {
[a setDuration:0.35 * ((fabs(location.x - x)) / maxX)];
[a setDuration:_slowAnimationDuration * ((fabs(location.x - x)) / maxX)];
[a setAnimationCurve:NSAnimationLinear];
}

Expand Down Expand Up @@ -344,4 +358,10 @@ - (BOOL)acceptsFirstResponder
return YES;
}

- (void)setDefaultDurations
{
_fastAnimationDuration = 0.20;
_slowAnimationDuration = 0.35;
}

@end

0 comments on commit bce123d

Please sign in to comment.