目标 C - 动画 alpha 变化



我一直在使用Flash,在一帧和另一帧之间更改alpha值非常容易。有没有办法在 xcode 4 中做到这一点?我正在制作一个徽标的动画,我需要第一个 png 消失,而第二个 png 开始出现。啧啧!

除了 esqew 的方法(在 iOS 4 之前可用,所以如果你不打算将工作限制在 iOS 4 上,你可能应该使用它),还有 [UIView animateWithDuration:animations:] ,它允许您在块中制作动画。 例如:

[UIView animateWithDuration:3.0 animations:^(void) {
    image1.alpha = 0;
    image2.alpha = 1;
}];

相当简单,但同样,这仅在iOS 4上可用,因此请记住这一点。

其他解决方案,淡入淡出:

//Disappear
[UIView animateWithDuration:1.0 animations:^(void) {
       SplashImage.alpha = 1;
       SplashImage.alpha = 0;
}
completion:^(BOOL finished){
//Appear
   [UIView animateWithDuration:1.0 animations:^(void) {
      [SplashImage setImage:[UIImage imageNamed:sImageName]];
      SplashImage.alpha = 0;
      SplashImage.alpha = 1;
 }];
}];

这其实很简单。将以下代码放在要播放动画的位置:

[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[image1 setAlpha:0];
[image2 setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above

您可以在本文档中阅读有关这些方法的更多信息。

如果您想使用您在对此问题的评论中提到的结构:

[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[[introAnimation objectAtIndex:0] setAlpha:0];
[[introAnimation objectAtIndex:1] setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above

。应该工作。

最新更新