【问题标题】:transitionWithView not working for swapping UIImage from UIImageViewtransitionWithView 无法从 UIImageView 交换 UIImage
【发布时间】:2014-05-15 06:41:17
【问题描述】:

根据我在对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];
    }

但事实并非如此。它根本不会为图像更改设置动画。我错过了什么?

【问题讨论】:

  • 您需要在前一个转换的完成块中启动下一个转换,以使它们按顺序发生。
  • 这是有道理的——但为什么改变会立即发生而不是两秒钟呢?

标签: objective-c uiview uiimageview uiimage objective-c-blocks


【解决方案1】:

两件事:

  1. 您需要在上一个转换的完成块中启动下一个转换,以使它们按顺序发生。
  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

【讨论】:

    猜你喜欢
    • 2012-03-11
    • 1970-01-01
    • 2012-07-03
    • 2012-07-15
    • 2019-08-07
    • 1970-01-01
    • 2013-10-13
    • 2011-12-06
    • 1970-01-01
    相关资源
    最近更新 更多