0

谁能给我一个例子,显示使用UIViewAnimationOptionTransitionCrossDissolve两个图像的交叉溶解效果。

我搜索了很多,但我找不到任何好的例子。

我可以举一些例子吗?

4

1 回答 1

0

以下代码是测试,创建两个 UIImageView 并将它们重叠还创建一个图像名称数组,然后对将在图像之间切换的下一个 (tag = 1) 和上一个 (tag = 0) 按钮使用以下操作:

- (void) switchImagesHandler:(int *)sender {
    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
    case 0:
        if (currentImg != 0) {
            currentImg--;
            [UIView animateWithDuration:0.3f animations:^{
                [firstImage setAlpha:0];
            }];

            [UIView animateWithDuration:0.3f animations:^{
                [firstImage setAlpha:1];
                [firstImage setImage:[UIImage imageNamed:[imagesArray objectAtIndex:currentImg]]];
            }completion:^(BOOL finished) {
                [secondImage setImage:[UIImage imageNamed:[imagesArray objectAtIndex:currentImg]]];
            }];
        }
        break;
    case 1:
        if (currentImg != [imagesArray count]) {
            currentImg++;
            [UIView animateWithDuration:0.3f animations:^{
                [firstImage setAlpha:0];
            }];
            [UIView animateWithDuration:0.3f animations:^{
                [firstImage setAlpha:1];
                [firstImage setImage:[UIImage imageNameds:[imagesArray objectAtIndex:currentImg]]];
            } completion:^(BOOL finished) {
                [secondImage setImage:[UIImage imageNameds:[imagesArray objectAtIndex:currentImg]]];
            }];
        }
        break;
    default:
        break;
    }
}
于 2013-03-19T11:01:54.583 回答