ios 动画 alpha 变化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6061885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:01:13  来源:igfitidea点击:

animation alpha change

objective-ciosanimationpngalpha

提问by Melisa D

I've always worked with Flash, and it's pretty easy to change the alpha values between one frame and another. Is there a way to do this in xcode 4? I'm animating a logo and I need the first png to disappear while the second one starts appearing. tnx!

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

回答by nil

Alternatively to esqew's method (which is available prior to iOS 4, so you should probably use it instead if you don't plan to limit your work to just iOS 4), there is also [UIView animateWithDuration:animations:], which allows you to do the animation in a block. For example:

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

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

Fairly simple, but again, this is available only on iOS 4, so keep that in mind.

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

回答by ChavirA

Other solution, fade in and fade out:

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

//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;
 }];
}];

回答by esqew

This is pretty simple actually. Place the following code where you want the animation to occur:

这实际上很简单。将以下代码放置在您希望出现动画的位置:

[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

You can read more about these methods in this document.

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

If you wanna work with a structure you referred to in your comment on this question:

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

[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

... should work.

... 应该管用。