CALayer、CCLayer、CAAnimation、CGAnimation的关系

1.UIView动画(块)——(指过渡效果的动画)

UIView视图的动画功能,可以使在更新或切换视图时有放缓节奏、产生流畅的动画效果,进而改善用户体验。UIView可以产生动画效果的变化包括:

位置变化:在屏幕上移动视图。

  • 大小变化:改变视图框架(frame)和边界。
  • 拉伸变化:改变视图内容的延展区域。
  • 改变透明度:改变视图的alpha值。
  • 改变状态:隐藏或显示状态。
  • 改变视图层次顺序:视图哪个前哪个后。
  • 旋转:即任何应用到视图上的仿射变换(transform)。
示例代码:

 1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLinear];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
 1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLinear];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10

 1 [UIView beginAnimations:nil context:nil];
2 //setAnimationCurve来定义动画加速或减速方式
3 [UIView setAnimaitonCurve:UIViewAnimationCurveLinear];
4 [UIView setAnimationDuration:2.7]; //动画时长
5 [UIView setAnimationTransition:transition forView:self.view cache:YES];
6 // operation>>>
7 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
8 // end<<<<<
9 [UIView commitAnimations];
10

基本动画效果:
UIViewAnimationTransitionNone 正常
UIViewAnimationTransitionFlipFromLeft 从左向右翻
UIViewAnimationTransitionFlipFromRight 从右向左翻
UIViewAnimationTransitionCurlUp 从下向上卷
UIViewAnimationTransitionCurlDown 从上向下卷

2.core方式:使用CATransition类

iPhone还支持Core Animation作为其QuartzCore架构的一部分,CA API为iPhone应用程序提供了高度灵活的动画解决方案。但是须知:CATransition只针对图层,不针对视图。图层是Core Animation与每个UIView产生联系的工作层面。 使用Core Animation时,应该将CATransition应用到视图的默认图层( [myView layer] 而不是视图本身。

使用CATransition类实现动画,只需要建立一个Core Animation对象,设置它的参数,然后把这个带参数的过渡添加到图层即可。
使用要引入QuartzCore.framework 代码#import <QuartzCore/QuartzCore.h>


示例代码:

 1 CATransition *transition = [CATransition animation];
2 transition.duration = 0.7;
3 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
4 transition.type = kCATransitionMoveIn;//{kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};
5
6 //更多私有{@"cube",@"suckEffect",@"oglFlip",@"rippleEffect",@"pageCurl",@"pageUnCurl",@"cameraIrisHollowOpen",@"cameraIrisHollowClose"};
7 transition.subtype = kCATransitionFromLeft;//{kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};
9 transition.delegate = self;
10 [self.view.layer addAnimation:transition forKey:nil]; 12 // 要做的
13 [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

动画嵌套使用:
[UIView animateWithDuration:1.25 animations:^{
CGAffineTransform newTransform = CGAffineTransformMakeScale(1.21.2);
[firstImageView setTransform:newTransform];
[secondImageView setTransform:newTransform];} 
completion:^(BOOL finished){
[UIView animateWithDuration:1.2 animations:^{
[firstImageView setAlpha:0];
[secondImageView setAlpha:0];} completion:^(BOOL finished){ 
[firstImageView removeFromSuperview]; 
[secondImageView removeFromSuperview]; }]; 
}];
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值