Created
December 3, 2009 17:53
-
-
Save evadne/248366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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