在xcode中自动淡化背景图像

时间:2013-11-29 08:31:36

标签: objective-c xcode animation uiimage fading

我试图在xcode中淡化几个背景图像。它们是动画但不褪色,请参阅下面的代码:

animationgirl.animationImages = [NSArray arrayWithObjects:

                             [UIImage imageNamed:@"girl1.png"],
                             [UIImage imageNamed:@"girl2.png"],
                             [UIImage imageNamed:@"girl3.png"],
                             [UIImage imageNamed:@"girl4.png"],
                             [UIImage imageNamed:@"girl5.png"],
                             [UIImage imageNamed:@"girl6.png"],
                             [UIImage imageNamed:@"girl7.png"],
                             [UIImage imageNamed:@"girl8.png"],
                             [UIImage imageNamed:@"girl9.png"],
                             [UIImage imageNamed:@"girl10.png"],
                             [UIImage imageNamed:@"girl11.png"],
                             [UIImage imageNamed:@"girl12.png"],
                             [UIImage imageNamed:@"girl13.png"],
                             [UIImage imageNamed:@"girl14.png"],nil];

[animationgirl setAnimationRepeatCount:0];
animationgirl.animationDuration = 1.8;
[animationgirl startAnimating];

1 个答案:

答案 0 :(得分:0)

在图像之间转换时,设置animationImages不支持额外的淡入/淡出效果。

你可以做的是创建一个CAKeyframeAnimation,并为它提供你试图制作动画的图像数组,例如:

    NSArray* contents = <NSArray of UIImages>;

    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
    [animation setCalculationMode:kCAAnimationLinear];
    [animation setDuration:contentsAnimationDuration];
    [animation setRepeatCount:HUGE_VALF];
    [animation setValues:contents];        

    [self.layer addAnimation:animation forKey:@"contents"];

为了使用Core Animation,您必须链接Quartz框架并包含相关的头文件。

你也可以category on CALayer I wrote for this purpose