Skip to content

Instantly share code, notes, and snippets.

@evadne
Created December 3, 2009 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evadne/248366 to your computer and use it in GitHub Desktop.
Save evadne/248366 to your computer and use it in GitHub Desktop.
- (void) shakeWindowHorizontally:(NSWindow *)inWindow duration:(float)inDuration vigour:(float)inVigour times:(int)inTimes {
// [self shakeWindowHorizontally:window duration:0.5 vigour:0.05 times:8];
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];
NSRect inFrame = [inWindow frame];
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, NSMinX(inFrame), NSMinY(inFrame));
int index;
for (index = 0; index < inTimes; ++index)
{
CGPathAddLineToPoint(shakePath, NULL, NSMinX(inFrame) - inFrame.size.width * inVigour, NSMinY(inFrame));
CGPathAddLineToPoint(shakePath, NULL, NSMinX(inFrame) + inFrame.size.width * inVigour, NSMinY(inFrame));
}
CGPathCloseSubpath(shakePath);
shakeAnimation.path = shakePath;
shakeAnimation.duration = inDuration;
[inWindow setAnimations:[NSDictionary dictionaryWithObject:shakeAnimation forKey:@"frameOrigin"]];
[[inWindow animator] setFrameOrigin:inFrame.origin];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment