更改 UIImageView 的图像时淡入淡出/溶解 [英] Fade/dissolve when changing UIImageView's image
问题描述
与其创建两个 UIImageViews
,不如简单地更改一个视图的 image
似乎是合乎逻辑的.如果我这样做,是否有两个图像之间的淡入淡出/交叉溶解而不是即时切换?
Rather than creating two UIImageViews
, it seems logical to simply change the image
of one view. If I do that, is there anyway of having a fade/cross dissolve between the two images rather than an instant switch?
推荐答案
另一种方法是使用预定义的 CAAnimation 转换:
Another way to do this is by using predefined CAAnimation transitions:
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
view1.hidden = YES;
view2.hidden = NO;
查看 Apple 的 View Transitions 示例项目:https://developer.apple.com/library/content/samplecode/ViewTransitions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007411
See the View Transitions example project from Apple: https://developer.apple.com/library/content/samplecode/ViewTransitions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007411
这篇关于更改 UIImageView 的图像时淡入淡出/溶解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!