#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)CALayer *imageLayer;
@end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImage *image1=[UIImage imageNamed:@""];
self.imageLayer=[CALayer layer];
self.imageLayer.frame=CGRectMake(, , , );
self.imageLayer.contents=(__bridge id)image1.CGImage;
[self.view.layer addSublayer:self.imageLayer]; [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:];
}
-(void)layerAnimation
{
/*隐式动画
UIImage *image2=[UIImage imageNamed:@"2"];
self.imageLayer.contents=(__bridge id)image2.CGImage;
*/
//显示动画,图片动画
UIImage *image2=[UIImage imageNamed:@""];
CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:@"contents"];
basicAnimation.fromValue=self.imageLayer.contents;
basicAnimation.toValue=(__bridge id)image2.CGImage;
basicAnimation.duration=3.0f; //bounds动画
CABasicAnimation *boundsAnimation=[CABasicAnimation animationWithKeyPath:@"bounds"];
boundsAnimation.fromValue=[NSValue valueWithCGRect:self.imageLayer.bounds];
boundsAnimation.toValue=[NSValue valueWithCGRect:CGRectMake(, , /2.0f, /2.0f)];
boundsAnimation.duration=3.0f; //组合动画
CAAnimationGroup *groupAnimation=[CAAnimationGroup animation];
groupAnimation.animations=@[basicAnimation,boundsAnimation];
groupAnimation.duration=3.0f; //设置layer动画结束后的值必须设置,否则的话会恢复动画之前的状态 self.imageLayer.contents=(__bridge id)image2.CGImage;
self.imageLayer.bounds=CGRectMake(, , /2.0f, /2.0f);
[self.imageLayer addAnimation:basicAnimation forKey:nil]; } @end

通过layer的contents属性来实现uiimageview的淡入切换的更多相关文章

  1. Swift - CALayer的contents属性动画

    Swift - CALayer的contents属性动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // LiveImageVi ...

  2. contents属性

    CALayer 有一个属性叫做contents,这个属性的类型被定义为id,意味着它可以是任何类型的对象.在这种情况下,你可以给contents属性赋任何值,你的app仍然能够编译通过.但是,在实践中 ...

  3. 利用layer的mask属性实现逐渐揭示的动画效果

    github上又看到个不错的动画(https://github.com/rounak/RJImageLoader),如图: 所以就想来自己实现以下 不试不知道,这个动画还真不是看上去那么简单,我自己想 ...

  4. 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可

    如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角而别的不变时 ...

  5. layer 的常用属性

    layer的各种属性代码示例: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading ...

  6. Layer的shadow属性

    Layer的shadow属性 Layer中的阴影都是可以做动画处理的. - (void)viewDidLoad { [super viewDidLoad]; CALayer *layer = [CAL ...

  7. iOS图片折叠效果:Layer的contentsRect属性和渐变层

    http://www.cocoachina.com/ios/20150722/12622.html 作者:@吖了个峥 授权本站转载. 前言 此次文章,讲述的是Layer的一个属性contentsRec ...

  8. CAEmitterLayer 粒子发射Layer的相关属性

    emitterCells:CAEmitterCell对象的数组,被用于把粒子投放到layer上 birthRate:可以通俗的理解为发射源的个数,默认1.0.当前每秒产生的真实粒子数为=CAEmitt ...

  9. layer图层常见属性

    把layer常见图层属性总结了一下^-^欢迎大家讨论~~~~来吧 ,代码属性 #import "CZViewController.h" @interface CZViewContr ...

随机推荐

  1. HDU2680 Choose the best route 最短路 分类: ACM 2015-03-18 23:30 37人阅读 评论(0) 收藏

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. [置顶] 2013 Multi-University Training Contest 8

    1003 Mine 简单sg的博弈题,我们走入了nim博弈的误区,后来发现改了三四个字符就过了....我只能说我是sbsbsbsbsbsb...判奇偶啊... #pragma comment(link ...

  3. Lotus 迁移到Exchange POC 之安装Exchange 2010!

    我们登录到Exchange 2010服务器,双击setup 安装Exchange 2010,双击setup.exe完成安装:

  4. 解决数据库datatime数据在DataGridView里不显示秒的解决

    在数据库中正确显示有分有秒,到dataset里的时候也有,但绑定到DataGridView里的时候就没有秒,解决办法: dataGridView1.Columns["record_time& ...

  5. Java Service Wrapper配置详解

    #encoding=UTF-8 # Configuration files must begin with a line specifying the encoding # of the the fi ...

  6. How to bind to data when the DataContext is not inherited【项目】

    http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherit ...

  7. git/github 使用

    原文:http://www.cnblogs.com/fnng/archive/2011/08/25/2153807.html git/github学习笔记 Posted on 2011-08-25 2 ...

  8. Android中全局Application的onCreate多次调用问题

    String processName = OsUtils.getProcessName(this, android.os.Process.myPid()); if (processName != nu ...

  9. cocos2dx shader实现灰度图android后台切换回来导致图像偏移的问题

    转自:http://www.tuicool.com/articles/U3URRrI 项目中经常会遇到将一张图像处理成灰色的需求,为了节省资源,一般不会让美术再做一套同样的灰度图,通常会通过代码处理让 ...

  10. VS 统计代码行数

    使用正则表达式 :    ^:b*[^:b#/]+.*$ 简单说明如下: ^:行头 $:行尾 +:一个或多个 *:0个或多个 :b:表示空白,匹配空格或者制表符 # 表示后面是include,/表示注 ...