Skip to content

Instantly share code, notes, and snippets.

@divol
Created July 8, 2011 14:42
Show Gist options
  • Select an option

  • Save divol/1071986 to your computer and use it in GitHub Desktop.

Select an option

Save divol/1071986 to your computer and use it in GitHub Desktop.
Shaking window
source : http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/
static int numberOfShakes = 4;static float durationOfShake = .5f;
static float vigourOfShake = 0.05f;
-(CAKeyframeAnimation *)shakeAnimation:(NSRect)frame
{
CAKeyframeAnimation *shakeAnimation =[CAKeyframeAnimation animation];
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, NSMinX(frame), NSMinY(frame));
int index;
for(index =0; index < numberOfShakes; ++index){
CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame)- frame.size.width * vigourOfShake, NSMinY(frame));
CGPathAddLineToPoint(shakePath, NULL, NSMinX(frame)+ frame.size.width * vigourOfShake, NSMinY(frame));
}
CGPathCloseSubpath(shakePath);
shakeAnimation.path = shakePath;
shakeAnimation.duration = durationOfShake;
return shakeAnimation;
}
NSWindow *w ;
[w setAnimations:[NSDictionarydictionaryWithObject:[self shakeAnimation:[windowframe]] forKey:@"frameOrigin"]];
[[w animator] setFrameOrigin[windowframe].origin];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment