-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MuZiLee
committed
Apr 9, 2016
1 parent
f1f46db
commit 7bc5393
Showing
37 changed files
with
3,659 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// CAAnimation+CCCategory.h | ||
// CCCategoryDemo | ||
// | ||
// Created by 李飞恒 on 16/4/5. | ||
// Copyright © 2016年 MuZiLee. All rights reserved. | ||
// | ||
|
||
#import <QuartzCore/QuartzCore.h> | ||
|
||
|
||
typedef NS_ENUM(NSUInteger, WAxis) | ||
{ | ||
WAxisX = 0, | ||
WAxisY, | ||
WAxisZ | ||
}; | ||
|
||
// 弧度 | ||
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI) | ||
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI)) | ||
|
||
|
||
@interface CAAnimation (CCCategory) | ||
|
||
/** | ||
* 慢慢透明,没了.... | ||
* @param 透明到底 | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityOneAnimation:(float)time; | ||
|
||
/** | ||
* 心跳 | ||
* @param 心跳时间 | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityForeverAnimation:(float)time; | ||
|
||
/** | ||
* breathing with fixed repeated times | ||
* | ||
* @param repeatTimes times | ||
* @param time duritaion, from clear to fully seen | ||
* | ||
* @return animation obj | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityTimesAnimation:(float)repeatTimes durTimes:(float)time; | ||
|
||
/** | ||
* //旋转 | ||
* | ||
* @param dur duration | ||
* @param degree rotate degree in radian(弧度) | ||
* @param axis axis | ||
* @param repeatCount repeat count | ||
* | ||
* @return animation obj | ||
*/ | ||
+ (CABasicAnimation *)cc_rotation:(float)dur degree:(float)degree direction:(WAxis)axis repeatCount:(int)repeatCount; | ||
|
||
|
||
/** | ||
* 放大 | ||
* | ||
* @param fromScale the original scale value, 1.0 by default | ||
* @param toScale target scale | ||
* @param time duration | ||
* @param repeatTimes repeat counts | ||
* | ||
* @return animaiton obj | ||
*/ | ||
+ (CABasicAnimation *)cc_scaleFrom:(CGFloat)fromScale toScale:(CGFloat)toScale durTimes:(float)time rep:(float)repeatTimes; | ||
/** | ||
* 摇摆 | ||
* | ||
* @param repeatTimes time | ||
* @param time duration | ||
* @param obj always be CALayer at present | ||
* @return aniamtion obj | ||
*/ | ||
+ (CAKeyframeAnimation *)cc_shake_AnimationRepeatTimes:(float)repeatTimes durTimes:(float)time forObj:(id)obj; | ||
|
||
|
||
@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,163 @@ | ||
// | ||
// CAAnimation+CCCategory.m | ||
// CCCategoryDemo | ||
// | ||
// Created by 李飞恒 on 16/4/5. | ||
// Copyright © 2016年 MuZiLee. All rights reserved. | ||
// | ||
|
||
#import "CAAnimation+CCCategory.h" | ||
#import <UIKit/UIKit.h> | ||
|
||
@implementation CAAnimation (CCCategory) | ||
|
||
/** | ||
* 慢慢透明,没了.... | ||
* @param 透明到底 | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityOneAnimation:(float)time { | ||
|
||
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"]; | ||
animation.fromValue=[NSNumber numberWithFloat:1.0]; | ||
animation.toValue=[NSNumber numberWithFloat:0.0]; | ||
animation.autoreverses = NO; | ||
animation.duration = time; | ||
animation.repeatCount = INFINITY; | ||
animation.removedOnCompletion=NO; | ||
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; | ||
animation.fillMode=kCAFillModeForwards; | ||
|
||
return animation; | ||
} | ||
|
||
/** | ||
* 心跳 | ||
* @param 心跳时间 | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityForeverAnimation:(float)time { | ||
|
||
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"]; | ||
animation.fromValue=[NSNumber numberWithFloat:1.0]; | ||
animation.toValue=[NSNumber numberWithFloat:0.0]; | ||
animation.autoreverses=YES; | ||
animation.duration=time; | ||
animation.repeatCount=FLT_MAX; | ||
animation.removedOnCompletion=NO; | ||
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; | ||
animation.fillMode=kCAFillModeForwards; | ||
animation.fromValue=[NSNumber numberWithFloat:0.0]; | ||
animation.toValue=[NSNumber numberWithFloat:1.0]; | ||
animation.autoreverses=YES; | ||
animation.duration=time; | ||
animation.repeatCount=FLT_MAX; | ||
animation.removedOnCompletion=NO; | ||
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; | ||
animation.fillMode=kCAFillModeForwards; | ||
return animation; | ||
} | ||
|
||
/** | ||
* breathing with fixed repeated times | ||
* | ||
* @param repeatTimes times | ||
* @param time duritaion, from clear to fully seen | ||
* | ||
* @return animation obj | ||
*/ | ||
+ (CABasicAnimation *)cc_opacityTimesAnimation:(float)repeatTimes durTimes:(float)time { | ||
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"]; | ||
animation.fromValue=[NSNumber numberWithFloat:1.0]; | ||
animation.toValue=[NSNumber numberWithFloat:0.0]; | ||
animation.repeatCount=repeatTimes; | ||
animation.duration=time; | ||
animation.removedOnCompletion=NO; | ||
animation.fillMode=kCAFillModeForwards; | ||
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; | ||
animation.autoreverses=YES; | ||
return animation; | ||
} | ||
|
||
/** | ||
* //rotate | ||
* | ||
* @param dur duration | ||
* @param degree rotate degree in radian(弧度) | ||
* @param axis axis | ||
* @param repeatCount repeat count | ||
* | ||
* @return animation obj | ||
*/ | ||
+ (CABasicAnimation *)cc_rotation:(float)dur degree:(float)degree direction:(WAxis)axis repeatCount:(int)repeatCount { | ||
CABasicAnimation* animation; | ||
NSArray *axisArr = @[@"transform.rotation.x", @"transform.rotation.y", @"transform.rotation.z"]; | ||
animation = [CABasicAnimation animationWithKeyPath:axisArr[axis]]; | ||
animation.fromValue = [NSNumber numberWithFloat:0]; | ||
animation.toValue= [NSNumber numberWithFloat:degree]; | ||
animation.duration= dur; | ||
animation.autoreverses= NO; | ||
animation.cumulative= YES; | ||
animation.removedOnCompletion=NO; | ||
animation.fillMode=kCAFillModeForwards; | ||
animation.repeatCount= repeatCount; | ||
animation.delegate= self; | ||
animation.fromValue= [NSNumber numberWithFloat:0]; | ||
|
||
return animation; | ||
} | ||
|
||
/** | ||
* scale animation | ||
* | ||
* @param fromScale the original scale value, 1.0 by default | ||
* @param toScale target scale | ||
* @param time duration | ||
* @param repeatTimes repeat counts | ||
* | ||
* @return animaiton obj | ||
*/ | ||
+ (CABasicAnimation *)cc_scaleFrom:(CGFloat)fromScale toScale:(CGFloat)toScale durTimes:(float)time rep:(float)repeatTimes { | ||
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"]; | ||
animation.fromValue = @(fromScale); | ||
animation.toValue = @(toScale); | ||
animation.duration = time; | ||
animation.autoreverses = YES; | ||
animation.repeatCount = repeatTimes; | ||
animation.removedOnCompletion = NO; | ||
animation.fillMode = kCAFillModeForwards; | ||
return animation; | ||
} | ||
|
||
/** | ||
* shake | ||
* | ||
* @param repeatTimes time | ||
* @param time duration | ||
* @param obj always be CALayer | ||
* @return aniamtion obj | ||
*/ | ||
+ (CAKeyframeAnimation *)cc_shake_AnimationRepeatTimes:(float)repeatTimes durTimes:(float)time forObj:(id)obj { | ||
NSAssert([obj isKindOfClass:[CALayer class]] , @"invalid target"); | ||
CGPoint originPos = CGPointZero; | ||
CGSize originSize = CGSizeZero; | ||
if ([obj isKindOfClass:[CALayer class]]) { | ||
originPos = [(CALayer *)obj position]; | ||
originSize = [(CALayer *)obj bounds].size; | ||
} | ||
CGFloat hOffset = originSize.width / 4; | ||
CAKeyframeAnimation* anim=[CAKeyframeAnimation animation]; | ||
anim.keyPath=@"position"; | ||
anim.values=@[ | ||
[NSValue valueWithCGPoint:CGPointMake(originPos.x, originPos.y)], | ||
[NSValue valueWithCGPoint:CGPointMake(originPos.x-hOffset, originPos.y)], | ||
[NSValue valueWithCGPoint:CGPointMake(originPos.x, originPos.y)], | ||
[NSValue valueWithCGPoint:CGPointMake(originPos.x+hOffset, originPos.y)], | ||
[NSValue valueWithCGPoint:CGPointMake(originPos.x, originPos.y)] | ||
]; | ||
anim.repeatCount=repeatTimes; | ||
anim.duration=time; | ||
anim.fillMode = kCAFillModeForwards; | ||
return anim; | ||
} | ||
|
||
|
||
@end |
Oops, something went wrong.