如何在xcode 4中的2个或更多背景图像之间设置Fade(alpha)动画

时间:2012-01-02 21:16:43

标签: xcode animation uiimageview fade alpha

我正在尝试在xcode 4中开发一个非常简单的应用程序。它是一个实用程序应用程序,有一个主视图,我想要在背景中为一系列照片制作动画,并使用简单的alpha淡入淡出,在2个或更多之间连续循环图片。

我在xcode用户文档中找到了一些代码,我已经修改过了(下面),但是我是新手,我想知道如何在现有项目中将以下代码设置为动态,放在哪里什么,创造什么出口等等:

// This method begins the first animation.

- (IBAction)showHideView:(id)sender

{

    [UIView beginAnimations:@"ShowHideView" context:nil];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationDidStopSelector:@selector(showHideDidStop:finished:context:)];



    // Make the animatable changes.

    secondImageView.alpha = 0.0;



    // Commit the changes and perform the animation.

    [UIView commitAnimations];

}



// Called at the end of the preceding animation.

- (void)showHideDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

{

    [UIView beginAnimations:@"ShowHideView2" context:nil];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationDelay:1.0];



    secondImageView.alpha = 1.0;



    [UIView commitAnimations];

}

1 个答案:

答案 0 :(得分:0)

我看到的确有两个问题,第一个是正确轨道上的动画代码,第二个是如何将它集成到应用程序中。

第二部分只是iPhone 101的基本内容,你最好看看Big Nerd Ranch的书籍。

对于第一部分,你上面做动画的方式是较旧的风格,并且比以前更复杂。

最简单的方法是使用动画块

这是一篇很好的介绍性文章,它实际上按照您的要求动画了图像的alpha: http://pragmaticstudio.com/blog/2010/7/28/ios4-blocks-1