我正在使用像这样的动画块进行图像转换
[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 ...每次我突然跳到下一张图像(这也发生在文本中)< / p>
有人能帮助我吗?
答案 0 :(得分:2)
您无法通过该方式设置图像或文本的更改动画。我这样做了,
-(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 = ...
对于您的子类的任何图像视图,当您更改它们时它将交叉淡化图像。