Notice in Figure 22.2 that each view
has a layer and each view is its layer’s
delegate. We’ll come back to the delegate relationship later in the
chapter.
So what’s the reason behind having views and
layers? Remember that
UIView is a subclass of
UIResponder. A view is really an abstraction
of a visible object that can be interacted with on the screen,
wrapped into a tidy class. A layer, on the
other hand, is all about the drawing.
Notice that layers interpret their size and position differently than views do. With a UIView, we typically define the frame of the view to establish its size and position. The origin of the frame rectangle is the upper-left corner of the view, and the size stretches right and down from the origin.
For a CALayer, instead of defining a frame, you set the bounds and position properties of the layer. The default setting for position is the center of the layer in its superlayer. (The anchorPoint property determines where the position lies inside the layer’s bounds, and its default value is (0.5, 0.5), otherwise known as the center.) Therefore, if you change the size of the layer but leave the position constant, the layer will remain centered on the same point.
Even though a layer doesn’t have a frame property, you can still get and set its “frame” by sending it the messages frame and setFrame:. When a layer is sent the message frame, it computes a rectangle from its position and bounds properties. Similarly, when sending a layer the message setFrame:, it does some math and then sets the bounds and position properties accordingly.
However, it is better to think of layers in terms of their position and bounds properties. The mental math needed to animate a layer is much simpler if you stick to setting the bounds and position properties directly.
blog
http://www.raywenderlich.com/2502/calayers-tutorial-for-ios-introduction-to-calayers-tutorial
Core Animation Layer(22),布布扣,bubuko.com
原文:http://www.cnblogs.com/zhangjl/p/3668922.html