Frame and Bounds of CAShapeLayer

前端 未结 4 1936
抹茶落季
抹茶落季 2020-12-31 11:26

I am working on CAShapeLayer.And trying to draw non-linear path.I want to set frame to CAShapeLayer.So i can use CGPathGetPathBoundingBox

4条回答
  •  不思量自难忘°
    2020-12-31 11:48

    When you modify the frame of a CALayer, you are modifying its size and position in the coordinate space of its superlayer. frame is a computed value, based on the object's bounds and position. In this case, the layer does not yet have a superlayer so its coordinate space is dimensionless. When you set the frame, the size gets carried through to the bounds property, but since any point in a dimensionless space is zero, the position will remain zero instead of what you'd intended.

    To solve this, you can set the bounds to set the layer's size, and position (which is a real non-computed property) in the coordinate space of the superlayer before adding it as a sublayer.

提交回复
热议问题