如何改变动画UIImage的持续时间?

时间:2015-02-15 03:06:23

标签: ios objective-c uiimage

我想在运行时期间更改UIImage UIImageView中的动画duration,但它的属性是只读的,并且没有像setDuration这样的方法。可能吗? 在viewDidLoad我称之为

-(void)prepareImage
{
    UIImage *image = [UIImage animatedImageNamed:@"image-" duration:1.0f];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:squirrelImage];
    self.imageView=imageView; //property with UIImageView
}

然后在某些事件上我这样做

-(UIImageView *)redrawedImage
{
    UIImageView *newImageView = self.imageView;

    //a lot of translations and scales

    return newImageView;
}

我想在不重置整个动画的情况下将动画的持续时间更改到内部。

1 个答案:

答案 0 :(得分:1)

UIImage * toImage = [UIImage imageNamed:@"myname.png"];
[UIView transitionWithView:self.imageView
                  duration:5.0f
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                  self.imageView.image = toImage;
                } completion:nil];

使用此代码可能有助于您....