UIImageView改变背景颜色和setImage在动画期间不工作



正如标题所说,这很奇怪,你同意吗?

所以,如果有人发现你的代码

imageView.backgroundColor = [UIColor greenColor]; 

imageView.image = [UIImage imageName:@"angryBird"];" 

不工作。只要记住,如果你的imageView是动画的,或者动画是否已经被删除。

---------- ---------------

在设置图像和改变动画UIImageView的背景之前停止动画。

UIImageView* imageView = [UIImageView alloc] init];
//......do sth. like setFrame ...
imageView.images = [NSArray arrayWithObjects....]; // set the animation images array 
imageView.animationDuration = 1.0;
[imageView startAnimating];
//......do sth.
[imageView stopAnimating];        // **** do not forget this!!!!! ****
imageView.backgroundColor = [UIColor greenColor];
imageView.image = [UIImage imageName:@"angryBird"];

当你的performSelector: withthobject: afterDey:1.0s,在选择器方法,也,你需要stopAnimating太,然后setImage或改变背景颜色。

动画完成后尝试更改背景颜色和更改图像。

试试这个:

[UIView animateWithDuration:1.0 animations:^(){} completion:^(BOOL finished){}];

试试这个,动画使用块

[UIView animateWithDuration:1.0 animations:^{
    }
    completion:^(BOOL finished)
    {
        [imageView setImage:[UIImage imageNamed:@"YOUR_IMAGE_NAME"]];
        [imageView setBackgroundColor:[UIColor greenColor]];

    }];

注意:它是imageNamed:而不是imageName:,我不确定这是如何编译的

试试下面的代码和performSelector: withthobject:afterDelay::

    [self performSelector:@selector(animationDidFinish:) withObject:nil
         afterDelay:instructions.animationDuration];

或使用dispatch_after:

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, instructions.animationDuration * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
         [self animationDidFinish];
    });

我希望它能帮助你

最新更新