-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work in progress, shake animation added
- Loading branch information
Giorgio Calderolla
committed
Jul 1, 2014
1 parent
7adbf8b
commit c9cf3ff
Showing
6 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface NSWindow (ShakeAnimation) | ||
|
||
- (void)performShakeAnimation; | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import <QuartzCore/QuartzCore.h> | ||
#import "NSWindow+ShakeAnimation.h" | ||
|
||
|
||
@implementation NSWindow (ShakeAnimation) | ||
|
||
- (void)performShakeAnimation { | ||
// Stolen from: http://stackoverflow.com/questions/10517386 | ||
static int numberOfShakes = 2; | ||
static float durationOfShake = 0.3f; | ||
static float vigourOfShake = 0.015f; | ||
|
||
CGRect frame = self.frame; | ||
CAKeyframeAnimation *shakeAnimation = CAKeyframeAnimation.animation; | ||
|
||
CGMutablePathRef shakePath = CGPathCreateMutable(); | ||
CGPathMoveToPoint(shakePath, NULL, NSMinX(frame), NSMinY(frame)); | ||
for (NSInteger 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; | ||
|
||
self.animations = @{@"frameOrigin": shakeAnimation}; | ||
[self.animator setFrameOrigin:self.frame.origin]; | ||
} | ||
|
||
@end |