根据我在回复this question时所读到的内容,以下内容应该有效:
UIImageView *snapshotView = [[UIImageView alloc]initWithFrame:self.window.frame];
[self.container.view addSubview:snapshotView];
for(int i = 1;i < 5; i = i +1){
UIImage *snapshotImage = [self blurredInboxBgImageWithRadius: (i * 5)];
[UIView transitionWithView:snapshotView
duration:2.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
snapshotView.image = snapshotImage;
} completion:nil];
}
但它没有。它根本不会为图像更改设置动画。我错过了什么?
答案 0 :(得分:2)
两件事:
UIViewAnimationOptionTransitionCrossDissolve
选项,而不是UIViewAnimationOptionCurveLinear
这里有一些代码我模拟了标签上的一系列转换:
@interface ViewController ()
@property (nonatomic) NSInteger iterationCount;
@property (strong, nonatomic) IBOutlet UILabel *label;
@end
@implementation ViewController
// called on button tap
- (IBAction)startTransitioning:(id)sender {
self.iterationCount = 0;
[self iterateTransition];
}
- (void)iterateTransition
{
if (self.iterationCount < 5) {
self.iterationCount++;
[UIView transitionWithView:self.label duration:2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.label.text = [NSString stringWithFormat:@"%d", self.iterationCount];
} completion:^(BOOL finished) {
[self iterateTransition];
}];
} else {
self.iterationCount = 0;
}
}
@end