Created
December 29, 2009 16:12
-
-
Save valexa/265394 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- (CAKeyframeAnimation *)negativeShake:(NSRect)frame{ | |
int numberOfShakes = 4; | |
float durationOfShake = 0.5f; | |
float vigourOfShake = 0.05f; | |
CAKeyframeAnimation *shakeAnim = [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); | |
shakeAnim.path = shakePath; | |
shakeAnim.duration = durationOfShake; | |
return shakeAnim; | |
} | |
- (IBAction)shakeBabyShake:(id)sender; | |
{ | |
NSString *key = @"frameOrigin"; | |
#if __i386__ | |
if ([NSView defaultAnimationForKey:key] == nil){ | |
#elif __x86_64__ | |
if ([NSWindow defaultAnimationForKey:key] == nil){ | |
#endif | |
NSLog(@"NSVindow not animatable for key '%@'",key); | |
}else { | |
[[NSApp keyWindow] setAnimations:[NSDictionary dictionaryWithObject:[self negativeShake:[[NSApp keyWindow] frame]] forKey:key]]; | |
[[[NSApp keyWindow] animator] setFrameOrigin:[[NSApp keyWindow] frame].origin]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment