Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, as promised, here is the code.</p> <p>First, I use a CAShapeLayer, and create it in a manner similar to above:</p> <pre><code>- (CALayer *)getSegment { CGRect layerFrame = CGRectMake ( 0, 0, s_viewRects[kASegment].size.width, s_viewRects[kASegment].size.height ); CAShapeLayer *ret = [CAShapeLayer layer]; [ret setFrame:layerFrame]; CGMutablePathRef thePath = CGPathCreateMutable (); CGPathAddLines ( thePath, nil, s_shapePoints, 7 ); [ret setPath:thePath]; return ret; } </code></pre> <p>Then, I set it into a main layer, like so, doing the transform along the way:</p> <pre><code>_top_left_element = [self getSegment]; frame = [self calculateRectForElement:_top_left_element]; CATransform3D transform = CATransform3DIdentity; transform = CATransform3DRotate(transform, M_PI_2, 0.0, 0.0, -1.0 ); [_top_left_element setTransform:transform]; [_top_left_element setFrame:frame]; [_main_element addSublayer:_top_left_element]; </code></pre> <p>The CATransform3DRotate is necessary, as the transform property of the layer is a 3D one. I use M_PI_2, as all transforms are in Radians (M_PI_2 is a convenient macro that means "90°"), and the -1 will make the rotate go counter-clockwise.</p> <p>calculateRectForElement is a function that figures out where everything is placed. It simply returns a rect that positions the element.</p> <p>_top_left_element is a class property that is a CALayer*.</p> <p>I did this, and Bjorn Strongintheram's your uncle.</p> <p><strong>UPDATE:</strong> <em>I wanted to add that you need to make sure that you CGPathRelease the layer's paths in the unload/destruct, or you will get a leak.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload