UIImage没有使用淡入淡出和动画块过渡来过渡 [英] UIImage is not transitioning using fade with animation block transition

查看:106
本文介绍了UIImage没有使用淡入淡出和动画块过渡来过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的动画块进行图像过渡

I am doing an image transition using an animation block like this

[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    self.songTitleLabel.text = currentSong.songTitle;
    self.artistNameLabel.text = currentSong.songArtist;
    self.songImageView.image = currentSong.songArtwork;
}completion:^(BOOL finished){
    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:currentSong.songLocation error:nil];
    [self.player setVolume:1.0];
    [self.player play];
}];

我不明白为什么我没有渐变过渡,我尝试了几种不同的UIAnimationOptionTransition ...并且每次我突然跳到下一张图像时(文本也会发生这种情况)

I don't understand why I don't have a fade transition, I have tried several different UIAnimationOptionTransition... and every time I just get an abrupt jump to the next image (this happens to the text as well)

有人可以帮我吗?

推荐答案

您不能以这种方式来动画化图像或文本的变化.我已经做到了,

You can't animate the changing of an image or text that way. I've done it like this,

-(IBAction)doStuff:(id)sender {

    [UIView transitionWithView:self.imageView
                      duration:1.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        [self.imageView setImage:[UIImage imageNamed:@"IMG_0081.JPG"]];
                    } completion:nil];

    [UIView transitionWithView:self.label2
                      duration:1.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        [self.label2 setText:@"New Text"];
                    } completion:nil];
}

如果要更改多个标签或图像视图,则最好创建一个子类,并覆盖setText:和setImage:.例如,对于setImage:这样,

If you're changing multiple labels or image views, it might be better to create a subclass, and override setText: and setImage:. For example, like this for setImage:,

-(void)setImage:(UIImage *)image {
    [UIView transitionWithView:self
                      duration:1.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                       [super setImage:image];
                    } completion:nil];
}

然后您就可以使用

self.imageView.image = ...

对于属于您子类的任何图像视图,当您更改图像时,它将使图像交叉褪色.

for any image view that's your subclass, and it will cross fade the images when you change them.

这篇关于UIImage没有使用淡入淡出和动画块过渡来过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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