通过layer的contents属性来实现uiimageview的淡入切换
2015-03-30 22:58
411 查看
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)CALayer *imageLayer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImage *image1=[UIImage imageNamed:@"1"]; self.imageLayer=[CALayer layer]; self.imageLayer.frame=CGRectMake(0, 0, 375, 300); self.imageLayer.contents=(__bridge id)image1.CGImage; [self.view.layer addSublayer:self.imageLayer]; [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:3]; } -(void)layerAnimation { /*隐式动画 UIImage *image2=[UIImage imageNamed:@"2"]; self.imageLayer.contents=(__bridge id)image2.CGImage; */ //显示动画,图片动画 UIImage *image2=[UIImage imageNamed:@"2"]; 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(0, 0, 375/2.0f, 300/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(0, 0, 375/2.0f, 300/2.0f); [self.imageLayer addAnimation:basicAnimation forKey:nil]; } @end
相关文章推荐
- iOS开发UIImage和UIImageView属性介绍,实现图片动画,实现开始/停止按钮效果
- 通过xml设定属性动画实现view的左右抖动和上下抖动
- 【iOS开发-9】UIImage和UIImageView属性介绍,实现图片动画,实现开始/停止按钮效果
- 关于动画的切换可以用UIImageView中的属性来实现。
- iOS开发——UIImageView的contentMode、裁剪和layer属性详解
- iOS开发——UIImageView的contentMode、裁剪和layer属性详解
- 通过javascript操作CSS3属性实现动画
- 结合UIImageView实现图片的移动和缩放
- android 通过WebView与javascript实现数据交互
- 实现UIImageView播放图片动画结束通知的demo
- UIImageView实现图片的移动和缩放
- 结合UIImageView实现图片的移动和缩放
- 结合UIImageView实现图片的移动和缩放
- 通过Response.Filter属性实现网站内容的动态GZIP压缩
- 利用UIImageView实现动画 .
- 通过js实现对html文件中控件属性的设置
- android RelativeLayout属性和使用, 实现上面view叠加在下面view之上的效果
- 继承PageBookView实现自己的“属性视图”
- 自定义Field Type的Control时,Field值得Get和Set是通过重载Value属性实现的
- 利用 UIImageView 实现全屏动画的代码例子