通过layer的contents属性来实现uiimageview的淡入切换
#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的淡入切换的更多相关文章
- Swift - CALayer的contents属性动画
Swift - CALayer的contents属性动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // LiveImageVi ...
- contents属性
CALayer 有一个属性叫做contents,这个属性的类型被定义为id,意味着它可以是任何类型的对象.在这种情况下,你可以给contents属性赋任何值,你的app仍然能够编译通过.但是,在实践中 ...
- 利用layer的mask属性实现逐渐揭示的动画效果
github上又看到个不错的动画(https://github.com/rounak/RJImageLoader),如图: 所以就想来自己实现以下 不试不知道,这个动画还真不是看上去那么简单,我自己想 ...
- 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角而别的不变时 ...
- layer 的常用属性
layer的各种属性代码示例: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading ...
- Layer的shadow属性
Layer的shadow属性 Layer中的阴影都是可以做动画处理的. - (void)viewDidLoad { [super viewDidLoad]; CALayer *layer = [CAL ...
- iOS图片折叠效果:Layer的contentsRect属性和渐变层
http://www.cocoachina.com/ios/20150722/12622.html 作者:@吖了个峥 授权本站转载. 前言 此次文章,讲述的是Layer的一个属性contentsRec ...
- CAEmitterLayer 粒子发射Layer的相关属性
emitterCells:CAEmitterCell对象的数组,被用于把粒子投放到layer上 birthRate:可以通俗的理解为发射源的个数,默认1.0.当前每秒产生的真实粒子数为=CAEmitt ...
- layer图层常见属性
把layer常见图层属性总结了一下^-^欢迎大家讨论~~~~来吧 ,代码属性 #import "CZViewController.h" @interface CZViewContr ...
随机推荐
- A JavaFX based Game Authoring System
http://www.mirkosertic.de/doku.php/javastuff/javafxgameauthoring ——————————————————————————————————— ...
- 支付结果回调v7核心,投保确认接口..
<?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST"&g ...
- TQImport3XLS.Map
property Map: TStrings; 设置数据集字段和Excel单元格之间定义映射属性以下列方式: FieldName=CellRange 导入单独的单元格 Field1=A1 Field1 ...
- DefWndProc/WndProc/IMessageFilter的区别
谈到Winform的消息处理,多数时候是通过事件处理程序进行的,但当没有对应的事件时通常的做法是声明DefWndProc或者WndProc或者IMessageFilter,经常在网上看见有文章将三者并 ...
- 【转】删除已经存在的 TFS Workspace
删除已经存在的 TFS Workspace 分类: TFS2010-03-03 16:59 1239人阅读 评论(2) 收藏 举报 serverpathcommandcachefilegoogle 工 ...
- 获取平台所有接口的IP和MAC地址
我们有时候会有获取网口的IP和MAC地址的需求.可以通过ioctl来获取. #include <sys/ioctl.h>#include <net/if.h>#include ...
- Linux下修改hostname
我维护两三个机房的数十台机器,开发用机器,运营用机器,自己工作机器也是ubuntu,有时开很多ssh,干的还是同样的事情,很容易搞混.所以需要一目了然的知道某台机器的情况,避免犯晕.这就需要修改主机名 ...
- DataTemplate和ControlTemplate的关系
DataTemplate和ControlTemplate的关系(转载自haiziguo) 一.ContentControl中的DataTemplate 在开始之前,我们先去看一下ContentCont ...
- Ehcache详细解读
[http://raychase.iteye.com/blog/1545906] Ehcache 是现在最流行的纯Java开源缓存框架. [通过编程方式使用EhCache ] //从class ...
- [翻译]比较ADO.NET中的不同数据访问技术(Performance Comparison:Data Access Techniques)
Performance Comparison: Data Access Techniques Priya DhawanMicrosoft Developer Network January 2002 ...