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

查看:28
本文介绍了如何为 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天全站免登陆