xcode 如何向 iPhone 应用程序添加动画?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2770918/
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-09-14 19:19:52  来源:igfitidea点击:

How do I add animation to an iPhone app?

iphoneobjective-cxcode

提问by james p

So I came from a Flash background where I can animate in timeline. I've completed the Beginning iPhone Development book and just realized that I still don't know how to get an animation in. I'm guessing I need to import png sequences?

所以我来自一个 Flash 背景,我可以在时间轴上制作动画。我已经完成了 iPhone 开发入门书,但刚刚意识到我仍然不知道如何输入动画。我猜我需要导入 png 序列?

Can anyone point me to an appropriate place to learn more about this topic? I want to make a game and my game objects need to animate.

任何人都可以给我指出一个合适的地方来了解有关此主题的更多信息吗?我想做一个游戏,我的游戏对象需要动画。

Thanks in advance!!

提前致谢!!

回答by drawnonward

The simplest type of animation, moving things around and fading in and out, can be done with a few static methods of UIVIew. You can affect the center, bounds, transform matrix and alpha level of one or more views.

最简单的动画类型,移动和淡入淡出,可以使用 UIVIew 的一些静态方法来完成。您可以影响一个或多个视图的中心、边界、变换矩阵和 alpha 级别。

[UIView beginAnimations:nil context:nil];
[fadingOutView setAlpha:0.0];
[slidingView setCenter:CGPointZero];
[shrinkingView setFrame:CGRectZero];
[fadingInView setAlpha:1.0];
[spinningView setTransform:CGAffineTransformMakeRotation( M_PI )];
[UIView commitAnimations];

Animations start with the current state of the view and interpolate to the state assigned between begin and commit animation. So if fadingInView already had an alpha of 1.0 (the default) there would be no change.

动画从视图的当前状态开始,并插入到开始动画和提交动画之间分配的状态。因此,如果fadingInView 的alpha 为1.0(默认值),则不会有任何变化。

If you are unfamiliar with static methods [UIView method];means call method on the class not an instance.

如果您不熟悉静态方法,则[UIView method];意味着在类上调用方法而不是实例。

Using other UIView static methods you can control several details of the animation. Every UIView has a CALayer that also has a few properties that can be animated, the most interesting of which is the 3D transform property.

使用其他 UIView 静态方法可以控制动画的几个细节。每个 UIView 都有一个 CALayer,它也有一些可以动画的属性,其中最有趣的是 3D 变换属性。

If the basic animation is not sufficient for you needs, you can either look into CAAnimation and related classes, or look to a third party animation library.

如果基本动画不能满足您的需求,您可以查看 CAAnimation 和相关类,或者查看第三方动画库。

I think the best place to start learning is in your code, since you are just transitioning from Flash. Look at the very bottom of UIView.h to see the animation methods. Make a few views and move them around.

我认为开始学习的最佳位置是在您的代码中,因为您只是从 Flash 过渡。查看 UIView.h 的最底部以查看动画方法。制作一些视图并移动它们。

回答by Jeff B

Take a look at cocos2d for iPhone. It has a good framework for handling sprites, animation (frame based and motion) as well as a lot of other stuff.

看看 iPhone 的 cocos2d。它有一个很好的框架来处理精灵、动画(基于帧和运动)以及许多其他东西。

http://www.cocos2d-iphone.org

http://www.cocos2d-iphone.org

You can of course do all off this on your own with core graphics and core animation, but an API like cocos2d takes care of a lot of the nitty gritty details for you.

当然,您可以使用核心图形和核心动画自行完成所有这些工作,但是像 cocos2d 这样的 API 会为您处理很多细节问题。

回答by ohho

The Beginning iPhone Development book does not talk much about animation. You may read more about animation from Apple documentation, and play with some samplesfrom Apple, such as the Touches.

《Beginning iPhone Development》一书没有过多地讨论动画。您可以从 Apple文档中阅读更多关于动画的信息,并使用Apple 的一些示例,例如Touches