UIView 动画与 CALayers
我正在努力使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用视图进行控制,使用图层进行养眼。 图层不接收事件,因此在这些情况下使用视图更容易,但是当您想要为精灵或背景等设置动画时,图层就有意义了。 事件直接通过图层传递到背景视图,因此您可以获得漂亮的视觉表示,而不会弄乱您的事件。 尝试覆盖仅用于视觉表示的视图,并且您必须自己将点击事件传递到底层视图。
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.
UIView
始终渲染到CALayer
。 当您使用UIView
方法对视图进行动画处理时,您实际上是在有效地操作底层CALayer
。如果您需要做简单的事情,请使用 UIView 方法。 对于更复杂的情况,或者如果您想要不与任何特定视图关联的图层,请使用
CALayers
。An
UIView
is always rendered to aCALayer
. When you useUIView
methods to animate a view, you are effectively manipulating the underlyingCALayer
.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, useCALayers
.去年我开发了很多应用程序。 这是我的经验法则:
I've done a bunch of apps in the past year. Here's my rule of thumb:
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.
我不确定我是否误解了 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.