• 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 

  • 相关阅读:
    SASS教程sass超详细教程
    浅谈angular2+ionic2
    深入理解JSON对象
    浅谈闭包
    响应式开发入门
    CSS之float属性归纳探讨
    新学期加油
    Good moring!
    async await的前世今生
    ASP.NET配置KindEditor文本编辑器-图文实例
  • 原文地址:https://www.cnblogs.com/zhangjl/p/3668922.html
Copyright © 2020-2023  润新知