Frage

Base on what I've read in the replies to this question the following should work:

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];
    }

But it doesn't. It does not animate the image changes at all. What am I missing?

War es hilfreich?

Lösung

Two things:

  1. You need to initiate the next transition in the completion block of the previous transition to have them happen sequentially.
  2. You need to use the UIViewAnimationOptionTransitionCrossDissolve option, not UIViewAnimationOptionCurveLinear

Here's some code I mocked up to do a sequence of transitions on a label:

@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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top