zoukankan      html  css  js  c++  java
  • Core Animation Layer(22)

    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 

  • 相关阅读:
    青岛理工大学邀请赛总结
    HDU 1232 并查集/dfs
    HDU 1556
    HDU 5228
    POJ1011
    线段树(数组实现)
    NOIP2008 普及组T1 ISBN号码 解题报告-S.B.S.
    NOIP2008 普及组T4 立体图 解题报告-S.B.S.(施工未完成)
    noip2008普及组4题题解-rLq
    noip2008普及组3题题解-rLq
  • 原文地址:https://www.cnblogs.com/zhangjl/p/3668922.html
Copyright © 2011-2022 走看看