如何在UIImageView中更改图像时实现动画

时间:2013-10-12 12:32:01

标签: objective-c animation uiimageview uiimage

我有 NSArray * pictureRefs ,其中包含图片名称。

这些图片将以UIImageView _mainImage 显示 到目前为止工作正常。
目前我使用左右两侧的按钮进行操作,请参见下图。这些按钮的标签与 pictureRefs 相对应。

变化非常直接,没有任何影响 我想像动画一样实现coverflow。

我是如何实现这一目标的?

我的代码切换图片

string =  [pictureRefs objectAtIndex:tag];
UIImage  *image  = [UIImage imageNamed:string];
[_mainImage setImage:image]; //Here I would like to make animations

enter image description here

1 个答案:

答案 0 :(得分:2)

单击任何按钮

时调用此方法
-(void)check_changeImage:(NSInteger)Value
{
    NSString *strimagename=[NSString stringWithFormat:@"dice_0%d.png",Value];//fetch image here as per you want 

 [UIView animateWithDuration:1.0 
                 animations:^{
                     imgviewDice1.image.alpha = 1.0;
                 }
                 completion:^(BOOL finished){

                     imgviewDice1.image=[UIImage imageNamed:strimagename];

                     // do something after the animation finished, 
                     // maybe releasing imageA if it's not used anymore...
                 }];

}

可能会有所帮助。