【发布时间】:2018-03-07 16:53:10
【问题描述】:
我正在尝试使用 SINGLE UIView 从一个图像淡入到另一个图像(是的! 已经看到关于 stackoverflow 的问答,它使用 2 个 UIViews - 在彼此)。
我有一个当前的 UIView 图像,想将其淡出并替换为另一个图像,然后将新图像淡入。
我尝试了以下方法:第一个的褪色,单独工作。
尝试#1)
// Fade original image - image already set in Storyboard
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[UIView setAnimationDelegate:self];
[_imgMirror setAlpha:0.0];
[UIView commitAnimations];
// Fade in new image
[_imgMirror setImage:[UIImage imageNamed:@"NewImage"]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[_imgMirror setAlpha:100.0];
[UIView commitAnimations];
这会在新图像中消失...旧图像不会消失。还尝试在两组代码之间“暂停”。
尝试 #2)
UIImage * toImage = [UIImage imageNamed:@"NewImage"];
[UIView transitionWithView:self.imgMirror
duration:0.33f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imgMirror.image = toImage;
} completion:NULL];
这会立即显示新图像,不会褪色或“CrossDissolves”。
尝试 #3)
// Fade original image - image already set in Storyboard
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[UIView setAnimationDelegate:self];
[_imgMirror setAlpha:0.0];
[UIView commitAnimations];
UIImage * toImage = [UIImage imageNamed:@"NewImage"];
[UIView transitionWithView:self.imgMirror
duration:0.33f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imgMirror.image = toImage;
} completion:NULL];
这与 #2 的结果相同。
知道有什么问题吗?
【问题讨论】:
标签: ios objective-c