【发布时间】:2014-06-24 03:42:11
【问题描述】:
我试图从一个 UIImage 交叉淡入淡出到另一个 UIImage 包含在 UIImageView 中。这似乎应该使用 UIView 动画来完成,代码如下:
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) IBOutlet UIImageView *sunImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_sunImageView.image = [UIImage imageNamed:@"sun1.png"];
UIImage *image = [UIImage imageNamed:@"sun3.png"];
[UIView transitionWithView:self.view
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
_sunImageView.image = image;
// _sunImageView.alpha = 0;
} completion:^(BOOL finished){
NSLog(@"FINISHED");
}];
}
IBOutlet 已正确连接,因为注释掉的代码将 .image alpha 从 1 设置为 0 可以正常工作。当此代码运行时,sun3.png 是显示的图像。 sun1.png,即使它是在动画之前设置的,也永远不会显示。
由于某种原因,此代码不会从 sun1.png 转换到 sun3.png。我已经搜索了很多,这是在图像视图中交叉溶解图像的建议解决方案,但它似乎对我不起作用。任何想法将不胜感激。
【问题讨论】:
标签: ios uiimageview uiimage uiviewanimationtransition