的UIImage使用褪色与动画块过渡不转换(UIImage is not transitioning

2019-10-30 11:20发布

我做像这样使用动画块的图像过渡

[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 ......每一次我刚刚得到的突然跳转到下一个图像(出现这种情况的文本以及)

有人可以帮我吗?

Answer 1:

你不能动画图像的变化或发短信的方式。 我已经做到了这样,

-(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:,

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

然后,您可以只使用,

self.imageView.image = ...

对于任何图像视图这是你的子类,它会淡入淡出的图像时,你改变他们。



文章来源: UIImage is not transitioning using fade with animation block transition