简体   繁体   English

动画化更改UIImageView的图像

[英]Animate changing the image of a UIImageView

There was another post with this question but none of the solutions worked. 有另一篇文章提到了这个问题,但是没有一种解决方案有效。 My problem is that I have a couple of imageViews that I need to change the images of. 我的问题是我有几个imageViews需要更改其图像。 It seems weird if I abruptly change them so I was wondering whether there was a way to fade the new image in. 如果我突然更改它们似乎很奇怪,所以我想知道是否有一种方法可以淡入新图像。

This is when I set one of the imageViews. 这是当我设置其中一个imageViews时。

self.imageView1.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg", [images objectAtIndex:newArray[0]]]];

Thanks 谢谢

Fading in an imageView can be achieved in multiple ways. imageView的淡入可以通过多种方式实现。 If you could post your code, (how do you change the view without fading-in now) others will be able to suggest easiest approach 如果您可以发布代码,(其他人如何能够在不褪色的情况下立即更改视图)将建议最简单的方法

Edit: Try animating the alpha like in the code below: 编辑:像下面的代码一样尝试设置alpha动画:

self.imageView1.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg", [images objectAtIndex:newArray[0]]]];
self.imgView1.alpha=0;
[UIView animateWithDuration:2.0
                      delay:0.1
                    options: UIViewAnimationCurveLinear
                 animations:^{
                    self.imgView1.alpha=1;
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

You can control the values of animateWithDuration and delay to suit your app 您可以控制animateWithDuration和delay的值以适合您的应用

Let us know if it works 让我们知道是否可行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM