Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c transitionWithView无法从UIImageView交换UIImage_Objective C_Uiview_Uiimageview_Uiimage_Objective C Blocks - Fatal编程技术网

Objective c transitionWithView无法从UIImageView交换UIImage

Objective c transitionWithView无法从UIImageView交换UIImage,objective-c,uiview,uiimageview,uiimage,objective-c-blocks,Objective C,Uiview,Uiimageview,Uiimage,Objective C Blocks,根据我在对以下内容的回复中所读到的内容,以下内容应该有效: 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 blurredInboxB

根据我在对以下内容的回复中所读到的内容,以下内容应该有效:

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];
    }
UIImageView*snapshotView=[[UIImageView alloc]initWithFrame:self.window.frame];
[self.container.view addSubview:snapshotView];
对于(int i=1;i<5;i=i+1){
UIImage*snapshotImage=[self-blurredInboxBgImageWithRadius:(i*5)];
[UIView转换WithView:snapshotView
持续时间:2.0华氏度
选项:UIViewAnimationOptionCurveLinear
动画:^{
snapshotView.image=快照图像;
}完成:无];
}
但事实并非如此。它根本不会设置图像更改的动画。我错过了什么?

两件事:


  • 您需要在前一个转换的完成块中启动下一个转换,以使它们按顺序发生
  • 您需要使用
    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
    
    @界面视图控制器()
    @属性(非原子)NSInteger迭代计数;
    @属性(强,非原子)IBUILabel*标签;
    @结束
    @实现视图控制器
    //点击按钮呼叫
    -(iAction)开始转换:(id)发送方{
    self.iterationCount=0;
    [自迭代转换];
    }
    -(void)迭代转换
    {
    if(self.iterationCount<5){
    self.iterationCount++;
    [UIView transitionWithView:self.label持续时间:2个选项:UIView动画选项Transition交叉融合动画:^{
    self.label.text=[NSString stringWithFormat:@“%d”,self.iterationCount];
    }完成:^(布尔完成){
    [自迭代转换];
    }];
    }否则{
    self.iterationCount=0;
    }
    }
    @结束
    
    您需要在上一个转换的完成块中启动下一个转换,以使它们按顺序进行。这是有道理的-但是为什么更改会立即发生而不是花两秒钟?