Permalink
Browse files

consolidated common animation code from both list controls into separ…

…ate SMFAnimation class
  • Loading branch information...
1 parent e0e078a commit 8bbd825793fcb6691383eb2906aa240a4f123614 Kevin Bradley committed Sep 18, 2011
View
@@ -16,7 +16,7 @@ SMFramework_FILES += SMFMoviePreviewController.m SMFControlFactory.m SMFAssetPr
SMFramework_FILES += SMFBookcaseController.m SMFComplexDropShadowControl.mm SMFComplexProcessDropShadowControl.m SMFPrefsMenuItem.m
SMFramework_FILES += SMFDictionaryEditor.m SMFDictionaryObjectEditor.m SMFCustomQueryMenu.m SMFPrefsSelectionItem.m
SMFramework_FILES += BRMediaShelfView_SMF.m
-SMFramework_FILES += SMFDropShadowControl.m SMFMockMenuItem.m
+SMFramework_FILES += SMFDropShadowControl.m SMFMockMenuItem.m SMFAnimation.m
SMFramework_FILES += Example/SMFExamples.m Example/SMFMoviePreviewDelegateAndDatasourceExample.m Example/SMFBookcaseDelegateAndDatasourceExample.m Example/SMFGridController.m
View
@@ -0,0 +1,26 @@
+//
+// SMFAnimation.h
+// SMFramework
+//
+// Created by Kevin Bradley on 9/18/11.
+// Copyright 2011 nito, LLC. All rights reserved.
+//
+
+
+@interface SMFAnimation : NSObject {
+
+}
+
+
++ (CAAnimationGroup *)zoomOutFadedToRect:(CGRect)outRect;
++ (CAAnimationGroup *)zoomInFadedToRect:(CGRect)inRect;
++ (CABasicAnimation *)fadeInAnimation;
++ (CABasicAnimation *)fadeOutAnimation;
++ (CABasicAnimation *)zoomOutToRect:(CGRect)outRect;
++ (CABasicAnimation *)zoomInToRect:(CGRect)inRect;
+
+ //deprecated
++ (CABasicAnimation *)zoomOutAnimation:(CATransform3D)zoomTransform;
++ (CABasicAnimation *)zoomInAnimation:(CATransform3D)zoomTransform;
+
+@end
View
@@ -0,0 +1,124 @@
+//
+// SMFAnimation.m
+// SMFramework
+//
+// Created by Kevin Bradley on 9/18/11.
+// Copyright 2011 nito, LLC. All rights reserved.
+//
+
+#import "SMFAnimation.h"
+
+#define ZOOM_TO_BOUNDS CGRectMake(0, 0, 108, 108)
+#define ZOOM_TO_POINT CGPointMake(591.5999755859375, 284.39999389648438)
+
+@implementation SMFAnimation
+
+
++ (CAAnimationGroup *)zoomOutFadedToRect:(CGRect)outRect
+{
+ CAAnimationGroup *outAnimation = [CAAnimationGroup animation];
+ [outAnimation setAnimations:[NSArray arrayWithObjects:[SMFAnimation zoomOutToRect:outRect], [SMFAnimation fadeOutAnimation], nil]];
+ outAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
+ outAnimation.fillMode = kCAFillModeForwards; //if you dont set this it reverts to its old mode before removing and looks really stupid.
+ outAnimation.removedOnCompletion = NO;
+ return outAnimation;
+
+}
+
++ (CAAnimationGroup *)zoomInFadedToRect:(CGRect)inRect
+{
+ CAAnimationGroup *outAnimation = [CAAnimationGroup animation];
+ [outAnimation setAnimations:[NSArray arrayWithObjects:[SMFAnimation zoomInToRect:inRect], [SMFAnimation fadeInAnimation], nil]];
+ outAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
+ outAnimation.fillMode = kCAFillModeForwards; //if you dont set this it reverts to its old mode before removing and looks really stupid.
+ outAnimation.removedOnCompletion = NO;
+ return outAnimation;
+
+}
+
++ (CABasicAnimation *)fadeInAnimation
+{
+ CABasicAnimation *theAnimation =[CABasicAnimation animationWithKeyPath:@"opacity"];
+ theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
+ theAnimation.toValue=[NSNumber numberWithFloat:1.0];
+ return theAnimation;
+}
+
++ (CABasicAnimation *)fadeOutAnimation
+{
+ CABasicAnimation *theAnimation =[CABasicAnimation animationWithKeyPath:@"opacity"];
+ theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
+ theAnimation.toValue=[NSNumber numberWithFloat:0.0];
+ return theAnimation;
+}
+
+
++ (CABasicAnimation *)zoomOutToRect:(CGRect)outRect
+{
+ CABasicAnimation *zoomOutAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
+ zoomOutAnimation.fromValue = [NSNumber numberWithInt:1.0];
+ if (CGRectEqualToRect(outRect, CGRectZero))
+ {
+ zoomOutAnimation.toValue = [NSValue valueWithCGRect:ZOOM_TO_BOUNDS];
+
+ } else {
+
+ zoomOutAnimation.toValue = [NSValue valueWithCGRect:outRect];
+
+ }
+
+ //zoomOutAnimation.duration = 0.25f;
+ return zoomOutAnimation;
+}
+
++ (CABasicAnimation *)zoomInToRect:(CGRect)inRect
+{
+ CABasicAnimation *zoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
+ if (CGRectEqualToRect(inRect, CGRectZero))
+ {
+ zoomInAnimation.fromValue = [NSValue valueWithCGRect:ZOOM_TO_BOUNDS];
+
+ } else {
+
+ zoomInAnimation.fromValue = [NSValue valueWithCGRect:inRect];
+ }
+
+ zoomInAnimation.toValue = [NSNumber numberWithInt:1.0];
+ return zoomInAnimation;
+}
+
+
+/*
+
+ deprecated code left in for posterity / laziness (in case we ever decide to grapple with transforms, a refresher/reminder
+
+ */
+
++ (CABasicAnimation *)zoomOutAnimation:(CATransform3D)zoomTransform //edits the transform directly, so this cant be properly paired with other animations - deprecated
+{
+
+ CABasicAnimation *zoomOutAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
+ //[zoomOutAnimation setDelegate:SMFAnimation];
+ zoomOutAnimation.repeatCount = 0;
+ zoomOutAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
+ zoomOutAnimation.toValue = [NSValue valueWithCATransform3D:zoomTransform];
+ zoomOutAnimation.fillMode = kCAFillModeForwards;
+ zoomOutAnimation.removedOnCompletion = NO;
+ return zoomOutAnimation;
+
+}
+
+
++ (CABasicAnimation *)zoomInAnimation:(CATransform3D)zoomTransform
+{
+
+ CABasicAnimation *zoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
+ zoomInAnimation.fromValue = [NSValue valueWithCATransform3D:zoomTransform];
+ zoomInAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
+ return zoomInAnimation;
+
+}
+
+
+
+@end
@@ -21,13 +21,6 @@
- (void)setZoomInPosition;
- (void)setZoomOutPosition;
-- (CAAnimationGroup *)zoomOutFadedAnimation;
-- (CAAnimationGroup *)zoomInFadedAnimation;
-- (CABasicAnimation *)fadeInAnimation;
-- (CABasicAnimation *)fadeOutAnimation;
-- (CABasicAnimation *)zoomOutAnimation:(CATransform3D)zoomTransform; //deprecated
-- (CABasicAnimation *)zoomOutAnimation;
-- (CABasicAnimation *)zoomInAnimation;
- (void)updateSender;
- (id)getListFromMenuItem:(id)menuItem;
View
@@ -9,8 +9,8 @@
#import "SMFDropShadowControl.h"
#import "SMFDefines.h"
#import "SMFMockMenuItem.h"
+#import "SMFAnimation.h"
-#define ZOOM_TO_BOUNDS CGRectMake(0, 0, 108, 108)
#define ZOOM_TO_POINT CGPointMake(591.5999755859375, 284.39999389648438)
/*
@@ -67,8 +67,6 @@ - (void)setZoomInPosition
pos.fromValue = [NSValue valueWithCGPoint:ZOOM_TO_POINT]; //
}
- pos.beginTime = 0;
- pos.duration = .25;
pos.toValue = [NSValue valueWithCGPoint:CGPointMake(640.0, 360.0)];
pos.fillMode = kCAFillModeForwards;
[[self layer] addAnimation:pos forKey:@"position"];
@@ -78,8 +76,6 @@ - (void)setZoomOutPosition
{
CABasicAnimation *pos = [CABasicAnimation animationWithKeyPath:@"position"];
pos.fromValue = [NSValue valueWithCGPoint:CGPointMake(640.0, 360.0)]; //
- pos.beginTime = 0;
- pos.duration = .25;
if (sender != nil)
{
pos.toValue = [NSValue valueWithCGPoint:[sender position]];
@@ -91,115 +87,6 @@ - (void)setZoomOutPosition
[[self layer] addAnimation:pos forKey:@"position"];
}
-
-- (CAAnimationGroup *)zoomOutFadedAnimation
-{
- CAAnimationGroup *outAnimation = [CAAnimationGroup animation];
- [outAnimation setAnimations:[NSArray arrayWithObjects:[self zoomOutAnimation], [self fadeOutAnimation], nil]];
- outAnimation.duration = .25;
- outAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- outAnimation.fillMode = kCAFillModeForwards; //if you dont set this it reverts to its old mode before removing and looks really stupid.
- outAnimation.removedOnCompletion = NO;
- return outAnimation;
-
-}
-
-- (CAAnimationGroup *)zoomInFadedAnimation
-{
- CAAnimationGroup *outAnimation = [CAAnimationGroup animation];
- [outAnimation setAnimations:[NSArray arrayWithObjects:[self zoomInAnimation], [self fadeInAnimation], nil]];
- outAnimation.duration = .25;
- outAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- outAnimation.fillMode = kCAFillModeForwards; //if you dont set this it reverts to its old mode before removing and looks really stupid.
- outAnimation.removedOnCompletion = NO;
- return outAnimation;
-
-}
-
-- (CABasicAnimation *)fadeInAnimation
-{
- CABasicAnimation *theAnimation =[CABasicAnimation animationWithKeyPath:@"opacity"];
- //theAnimation.duration=.25;
- theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
- theAnimation.toValue=[NSNumber numberWithFloat:1.0];
- return theAnimation;
-}
-
-- (CABasicAnimation *)fadeOutAnimation
-{
- CABasicAnimation *theAnimation =[CABasicAnimation animationWithKeyPath:@"opacity"];
- //theAnimation.duration=.25;
- theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
- theAnimation.toValue=[NSNumber numberWithFloat:0.0];
- return theAnimation;
-}
-
-- (CABasicAnimation *)zoomOutAnimation:(CATransform3D)zoomTransform //edits the transform directly, so this cant be properly paired with other animations
-{
-
- CABasicAnimation *zoomOutAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- //[zoomOutAnimation setDelegate:self];
- zoomOutAnimation.beginTime = 0;
- zoomOutAnimation.repeatCount = 0;
- zoomOutAnimation.timeOffset = 1;
- zoomOutAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
- zoomOutAnimation.toValue = [NSValue valueWithCATransform3D:zoomTransform];
- zoomOutAnimation.duration = 0.25f;
- zoomOutAnimation.fillMode = kCAFillModeForwards;
- zoomOutAnimation.removedOnCompletion = NO;
- return zoomOutAnimation;
-
-}
-
-- (CABasicAnimation *)zoomOutAnimation
-{
- CABasicAnimation *zoomOutAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- zoomOutAnimation.beginTime = 0;
- zoomOutAnimation.fromValue = [NSNumber numberWithInt:1.0];
- if (sender != nil)
- {
- zoomOutAnimation.toValue = [NSValue valueWithCGRect:[sender bounds]];
-
- } else {
-
- zoomOutAnimation.toValue = [NSValue valueWithCGRect:ZOOM_TO_BOUNDS];
-
- }
-
- //zoomOutAnimation.duration = 0.25f;
- return zoomOutAnimation;
-}
-
-- (CABasicAnimation *)zoomInAnimation
-{
- CABasicAnimation *zoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- zoomInAnimation.beginTime = 0;
- if (sender != nil)
- {
- zoomInAnimation.fromValue = [NSValue valueWithCGRect:[sender bounds]];
-
- } else {
-
- zoomInAnimation.fromValue = [NSValue valueWithCGRect:ZOOM_TO_BOUNDS];
- }
-
- zoomInAnimation.toValue = [NSNumber numberWithInt:1.0];
- zoomInAnimation.duration = 0.25f;
- return zoomInAnimation;
-}
-
-- (CABasicAnimation *)zoomInAnimation:(CATransform3D)zoomTransform
-{
-
- CABasicAnimation *zoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- zoomInAnimation.beginTime = 0;
- zoomInAnimation.fromValue = [NSValue valueWithCATransform3D:zoomTransform];
- zoomInAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
- zoomInAnimation.duration = 0.25f;
- return zoomInAnimation;
-
-}
-
-(BOOL)avoidsCursor //of course it was easier than i was making it!!
{
return TRUE;
@@ -210,7 +97,12 @@ - (void)removeFromParent
if (self.isAnimated == TRUE)
{
//CATransform3D zoomTransform = CATransform3DMakeScale(0.1, 0.1, 1.0);
- CAAnimationGroup *zoomOutAnimation = [self zoomOutFadedAnimation];
+ CAAnimationGroup *zoomOutAnimation = nil;
+ if (sender != nil)
+ zoomOutAnimation = [SMFAnimation zoomOutFadedToRect:[sender bounds]];
+ else
+ zoomOutAnimation = [SMFAnimation zoomOutFadedToRect:CGRectZero];
+
[zoomOutAnimation setDelegate:self];
[self setZoomOutPosition];
[zoomOutAnimation setValue:@"removeFromParent" forKey:@"Name"];
@@ -231,15 +123,19 @@ -(void)addToController:(BRController *)ctrl
if (self.isAnimated == TRUE)
{
+ CAAnimationGroup *zoomInAnimation = nil;
+
if (sender != nil)
{
- [self updateSender];
+ [self updateSender]; //fixes the sender to have a proper X value for purposes of zooming in and out
+
+ zoomInAnimation = [SMFAnimation zoomInFadedToRect:[sender bounds]];
+ } else {
+ zoomInAnimation = [SMFAnimation zoomInFadedToRect:CGRectZero];
}
- [self setZoomInPosition];
- //CATransform3D zoomTransform = CATransform3DMakeScale(0.1, 0.1, 1.0);
- //CABasicAnimation *zoomInAnimation = [self zoomInAnimation];
- CAAnimationGroup *zoomInAnimation = [self zoomInFadedAnimation];
+
+ [self setZoomInPosition]; //wish there was some way for me to implement this into the animation class, but its specific to self
[zoomInAnimation setValue:@"zoomInAnimation" forKey:@"Name"];
[zoomInAnimation setDelegate:self];
@@ -54,12 +54,6 @@
-(void)addToController:(BRController *)ctrl;
- (void)setZoomInPosition;
- (void)setZoomOutPosition;
-- (CAAnimationGroup *)zoomOutFadedAnimation;
-- (CAAnimationGroup *)zoomInFadedAnimation;
-- (CABasicAnimation *)fadeInAnimation;
-- (CABasicAnimation *)fadeOutAnimation;
-- (CABasicAnimation *)zoomOutAnimation;
-- (CABasicAnimation *)zoomInAnimation;
- (void)updateSender;
- (id)getListFromMenuItem:(id)menuItem;
Oops, something went wrong.

0 comments on commit 8bbd825

Please sign in to comment.