假设我正在添加一个UIImageView,我希望将其溶解在一起,而不是出现锐利,它会更加流畅地显示出来。这可能吗?
正如this回答中所述,您可以将更改解除为:
UIImage * toImage = [UIImage imageNamed:@"myname.png"];
[UIView transitionWithView:self.imageView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = toImage;
} completion:nil];
只是好奇添加剂是否可以得到类似的处理。
答案 0 :(得分:1)
尝试最初添加一个完全空白的图像,然后将其更改为您选择的图像 - 这将为您提供所需的“添加时溶解动画”。
答案 1 :(得分:1)
您的代码将执行您想要的操作,只需尝试使用以下代码: (顺便说一下:不要调用transitionWithView:在viewDidLoad:中,imageView的动画在viewDidLoad中不起作用)
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
ViewController.m #import“ViewController.h”
@interface ViewController ()
@property (strong,nonatomic) UIImage * imageOne;
@property (strong,nonatomic) UIImage * imageTwo;
@end
@implementation ViewController
- (void)viewDidLoad
{
self.imageOne = [UIImage imageNamed:@"a.jpg"];
self.imageTwo = [UIImage imageNamed:@"b.jpg"];
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//init imageView here
if(self.imageView.image == nil){
[self performSelector:@selector(handleButtonTouch:) withObject:nil afterDelay:1];
}
}
- (IBAction)handleButtonTouch:(id)sender {
UIImage * toImage = ([self.imageView.image isEqual:self.imageOne]) ? self.imageTwo : self.imageOne;
[UIView transitionWithView:self.imageView
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = toImage;
}
completion:NULL];
}
@end