如何动画UIImageView中的图像变化? [英] How to animate the change of image in an UIImageView?

查看:135
本文介绍了如何动画UIImageView中的图像变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带图像的UIImageView。现在我有一个全新的图像(图形文件),并希望在这个UIImageView中显示它。如果我只是设置

I have an UIImageView with an image. Now I have a completely new image (graphic file), and want to display that in this UIImageView. If I just set

myImageView.image = newImage;

新图像立即可见。不可动画。

the new image is visible immediately. Not animatable.

我希望它能很好地淡入新图像。我想也许有一个更好的解决方案,而不仅仅是创建一个新的UIImageView并与动画混合?

I want it to nicely fade into the new image. I thought maybe there's a better solution than just creating a new UIImageView on top of that and blending with animation?

推荐答案

我不是确定你是否可以使用淡入淡出效果为UIViews设置动画,因为似乎所有支持的视图过渡都在 UIViewAnimationTransition 枚举中定义。使用CoreAnimation可以实现褪色效果。此方法的示例示例:

I am not sure if you can animate UIViews with fade effect as it seems all supported view transitions are defined in UIViewAnimationTransition enumeration. Fading effect can be achieved using CoreAnimation. Sample example for this approach:

#import <QuartzCore/QuartzCore.h>
...
imageView.image = [UIImage imageNamed:(i % 2) ? @"3.jpg" : @"4.jpg"];

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;

[imageView.layer addAnimation:transition forKey:nil];

这篇关于如何动画UIImageView中的图像变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆