QuartzCore框架 CATransition动画
2016-05-30 16:32
651 查看
#define kBackgroundColor1 [UIColor redColor]
#define kBackgroundColor2 [UIColor yellowColor]
#define kDurationTime 0.7f
@interface ViewController ()
@property (nonatomic,assign) int subType;
@end
typedef enum : NSUInteger{
Fade = 1, //淡入淡出
Push, //推挤
Reveal, //揭开
MoveIn, //覆盖
Cube, //立方体
SuckEffect, //吸附
OglFlip, //翻转
RippleEffect, //波纹
PageCurl, //翻页
PageUnCurl, //反翻页
CameraIrisHollowOpen, //开镜头
CameraIrisHollowClose, //关镜头
CurlDown, //下翻转
CurlUp, //上翻转
FlipFromLeft, //左翻转
FlipFromRight, //右翻转
}AnimationType;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.subType = 0;
[self showViewBgWithName:kBackgroundColor2];
}
- (IBAction)tagButtonAction:(id)sender {
UIButton *button = sender;
AnimationType animationType = button.tag;
NSString *subtypeString;
// 设置方向
switch (self.subType) {
case 0:
subtypeString = kCATransitionFromLeft;
break;
case 1:
subtypeString = kCATransitionFromBottom;
break;
case 2:
subtypeString = kCATransitionFromRight;
break;
case 3:
subtypeString = kCATransitionFromTop;
break;
default:
break;
}
_subType += 1;
if (_subType > 3) {
_subType = 0;
}
// QuartzCore 动画
switch (animationType) {
case Fade:
[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
break;
case Push:
[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
break;
case Reveal:
[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
break;
case MoveIn:
[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
break;
case Cube:
[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
break;
case SuckEffect:
[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
break;
case OglFlip:
[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
break;
case RippleEffect:
[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
break;
case PageCurl:
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
break;
case PageUnCurl:
[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowOpen:
[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowClose:
[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
break;
case CurlDown:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
break;
case CurlUp:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
break;
case FlipFromLeft:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
break;
case FlipFromRight:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
break;
default:
break;
}
static int i = 0;
if (i == 0) {
[self showViewBgWithName:kBackgroundColor1];
i = 1;
}else{
[self showViewBgWithName:kBackgroundColor2];
i = 0;
}
}
- (void)showViewBgWithName:(UIColor *)color{
self.view.backgroundColor = color;
}
#pragma mark CATransition 动画实现
- (void)transitionWithType:(NSString *)type WithSubtype:(NSString *)subType ForView:(UIView *)View{
//创建Catransition对象
CATransition *animation = [CATransition animation];
//设置运动时间
animation.duration = kDurationTime;
//设置运动type
animation.type = type;
if (subType != nil) {
// 设置子类
animation.subtype = subType;
}
// 设置运动速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[View.layer addAnimation:animation forKey:@"animation"];
}
#pragma mark UIView 实现动画
- (void)animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition)transition{
[UIView animateWithDuration:kDurationTime animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:view cache:YES];
}];
}
@end
#define kBackgroundColor2 [UIColor yellowColor]
#define kDurationTime 0.7f
@interface ViewController ()
@property (nonatomic,assign) int subType;
@end
typedef enum : NSUInteger{
Fade = 1, //淡入淡出
Push, //推挤
Reveal, //揭开
MoveIn, //覆盖
Cube, //立方体
SuckEffect, //吸附
OglFlip, //翻转
RippleEffect, //波纹
PageCurl, //翻页
PageUnCurl, //反翻页
CameraIrisHollowOpen, //开镜头
CameraIrisHollowClose, //关镜头
CurlDown, //下翻转
CurlUp, //上翻转
FlipFromLeft, //左翻转
FlipFromRight, //右翻转
}AnimationType;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.subType = 0;
[self showViewBgWithName:kBackgroundColor2];
}
- (IBAction)tagButtonAction:(id)sender {
UIButton *button = sender;
AnimationType animationType = button.tag;
NSString *subtypeString;
// 设置方向
switch (self.subType) {
case 0:
subtypeString = kCATransitionFromLeft;
break;
case 1:
subtypeString = kCATransitionFromBottom;
break;
case 2:
subtypeString = kCATransitionFromRight;
break;
case 3:
subtypeString = kCATransitionFromTop;
break;
default:
break;
}
_subType += 1;
if (_subType > 3) {
_subType = 0;
}
// QuartzCore 动画
switch (animationType) {
case Fade:
[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
break;
case Push:
[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
break;
case Reveal:
[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
break;
case MoveIn:
[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
break;
case Cube:
[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
break;
case SuckEffect:
[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
break;
case OglFlip:
[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
break;
case RippleEffect:
[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
break;
case PageCurl:
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
break;
case PageUnCurl:
[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowOpen:
[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowClose:
[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
break;
case CurlDown:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
break;
case CurlUp:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
break;
case FlipFromLeft:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
break;
case FlipFromRight:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
break;
default:
break;
}
static int i = 0;
if (i == 0) {
[self showViewBgWithName:kBackgroundColor1];
i = 1;
}else{
[self showViewBgWithName:kBackgroundColor2];
i = 0;
}
}
- (void)showViewBgWithName:(UIColor *)color{
self.view.backgroundColor = color;
}
#pragma mark CATransition 动画实现
- (void)transitionWithType:(NSString *)type WithSubtype:(NSString *)subType ForView:(UIView *)View{
//创建Catransition对象
CATransition *animation = [CATransition animation];
//设置运动时间
animation.duration = kDurationTime;
//设置运动type
animation.type = type;
if (subType != nil) {
// 设置子类
animation.subtype = subType;
}
// 设置运动速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[View.layer addAnimation:animation forKey:@"animation"];
}
#pragma mark UIView 实现动画
- (void)animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition)transition{
[UIView animateWithDuration:kDurationTime animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:view cache:YES];
}];
}
@end
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- 利用jquery制作滚动到指定位置触发动画
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
- jQuery实现带有洗牌效果的动画分页实例
- jQuery动画效果相关方法实例分析