Created
July 8, 2011 14:42
-
-
Save divol/1071986 to your computer and use it in GitHub Desktop.
Shaking window
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
| 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