UIView 动画与 CALayers

发布于 2024-07-27 15:51:49 字数 378 浏览 11 评论 0原文

我正在努力使用 CALayer 来概念化动画,而不是 UIView 自己的动画方法。 将“核心动画”放入其中,好吧,也许有人可以从高层次上阐明这些概念,以便我可以更好地可视化正在发生的事情以及为什么我想要迁移 UIView 动画(我是现在已经很熟悉了)到iPhone上的CALayer动画。 Cocoa-Touch 中的每个视图都会自动获得一个图层。 而且,看来您可以为一个和/或另一个设置动画?!?甚至将它们混合在一起?!? 但为什么? 线在哪里? 各自的优点/缺点是什么?

核心动画编程指南立即跳转到层和层。 计时类和我认为需要退后一步,理解为什么这些不同的部分存在以及彼此之间的关系。

I'm struggling with conceptualizing animations with a CALayer as opposed to UIView's own animation methods. Throw "Core Animation" into this and, well, maybe someone can articulate these concepts from a high level so I can better visualize what's happening and why I'd want to migrate UIView animations (which I'm quite familiar with now) to CALayer animations on the iPhone. Every view in Cocoa-Touch automatically gets a layer. And, it seems, you can animate one and/or the other?!? Even mix them together?!? But why? Where's the line? What's the pro/con to each?

The Core Animation Programming Guide immediately jumps into Layer & Timing Classes and I think need to take a step back and understand why these varied pieces exist and how relate to each other.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

幽梦紫曦~ 2024-08-03 15:51:49

使用视图进行控制,使用图层进行养眼。 图层不接收事件,因此在这些情况下使用视图更容易,但是当您想要为精灵或背景等设置动画时,图层就有意义了。 事件直接通过图层传递到背景视图,因此您可以获得漂亮的视觉表示,而不会弄乱您的事件。 尝试覆盖仅用于视觉表示的视图,并且您必须自己将点击事件传递到底层视图。

Use views for control and layers for eye candy. Layers don't receive events so it's easier to use a view for those cases, but when you want to animate a sprite or backgrounds, etc., layers make sense. Events pass right through layers to the backing view so you can have a pretty visual representation without messing up your events. Try to overlay a view that you're just using for visual representation and you'll have to pass tap events through to the underlying view yourself.

后知后觉 2024-08-03 15:51:49

UIView 始终渲染到 CALayer。 当您使用 UIView 方法对视图进行动画处理时,您实际上是在有效地操作底层 CALayer

如果您需要做简单的事情,请使用 UIView 方法。 对于更复杂的情况,或者如果您想要不与任何特定视图关联的图层,请使用CALayers

An UIView is always rendered to a CALayer. When you use UIView methods to animate a view, you are effectively manipulating the underlying CALayer.

If you need to do simple things, use the UIView methods. For more complex situatins, or if you want layers not associated with any view in particular, use CALayers.

强者自强 2024-08-03 15:51:49

去年我开发了很多应用程序。 这是我的经验法则:

  1. 使用 UIView 直到它不能满足您的要求。
  2. 然后转到CoreAnimation。 但在您深入了解之前...
  3. 如果您编写多个动画,请使用 Cocos2D。

I've done a bunch of apps in the past year. Here's my rule of thumb:

  1. Use UIView until it doesn't do what you want.
  2. Then move to CoreAnimation. But before you get into it too much...
  3. If you write more than a few animations, use Cocos2D.
掀纱窥君容 2024-08-03 15:51:49

UIView 变换只是 2D 并且仅限于此,但是 LAyer 变换可以是 3D,如果您想做 3D 的东西,您应该使用它们,如果您更改 UIView 变换或 CALayer 变换,UIView 动画将起作用。 因此,在基本层面上,当您使用图层而不是视图时,您可以进行更多操作。

UIView transforms are only 2D and are restricted to that, LAyer transforms however can be 3D and you should use those if you want to do 3D stuff, UIView animation will work if you change either the UIView transform or the CALayer transform. So at a basic level, you can do a lot more manipulation when you are working with a Layer rather than the View.

拔了角的鹿 2024-08-03 15:51:49

我不确定我是否误解了 Chris 对“Cocos2D 在哪些方面做得更好?那么,关于触摸事件处理和 openGL ES 中缺少的许多其他内容,您是否还有其他问题?”的回答。

听起来这个答案表明 Cocos2D 不是基于 OpenGL ES 框架,但实际上它是基于的。 虽然它是一个很棒的 2D 游戏引擎,但它确实在大部分渲染中实现了 OpenGL - 附加到物理库,它为动画提供了许多非常有趣的可能性 - Chris 是正确的 - 它确实少了很多编码。

I am not sure if I am misunderstanding Chris' response to "What's Cocos2D doing better? Don't you have other problems then, regarding the touch event handling and many other stuff that misses in openGL ES?"

It sounds like the answer suggests Cocos2D is not based on the OpenGL ES framework when in fact it actual is. While it is a great 2D game engine it does implement OpenGL for much of it's rendering - attached to a physics library it allows for a lot of very interesting possibilities for animation - and Chris is correct - it is a lot less coding indeed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文