Note that there are some explanatory texts on larger screens.

plurals
  1. POOn iOS, why does setting a layer's sublayerTransform turn itself to act like CATranformLayer?
    primarykey
    data
    text
    <p>It is known that the <code>zPosition</code> of the layers only determines which layer cover up which layer. Whether it is a <code>zPosition</code> of 10 or 1000 won't affect its position.</p> <p>That is, unless if we <a href="https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CATransformLayer_class/Reference/Reference.html" rel="noreferrer">use <code>CATransformLayer</code> to contain those layers</a>, then the <code>zPosition</code> of those layers will affect the layers' position.</p> <p>However, the following code running in iOS 5.1.1 does make the <code>zPosition</code> alter the position of the layers... you can try it in a new Single View App, and add the following code to <code>ViewController.m</code>. If the <code>zPosition</code> of <code>layer2</code> is changed from <code>88</code> to <code>188</code>, we can see that the layer moves accordingly. So no <code>CATransformLayer</code> is in the code; why will it behave like that? (Please quote Apple docs or any reference).</p> <p>Also related is, if the line <code>self.view.layer.sublayerTransform = transform3D;</code> is changed to <code>self.view.layer.transform = transform3D;</code> then the <code>zPosition</code> will have no effect on the position. But <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html#//apple_ref/doc/uid/TP40006082-SW1" rel="noreferrer">according to the Apple docs, <code>transform</code> and <code>sublayerTransform</code> only differ in whether self is transformed or not</a>:</p> <blockquote> <p>Two layer properties specify transform matrices: <code>transform</code> and <code>sublayerTransform</code>. The matrix specified by the <code>transform property</code> is applied to the layer and its sublayers relative to the layer's <code>anchorPoint</code>. [...] The matrix specified by the <code>sublayerTransform</code> property is applied only to the layer’s sublayers, rather than to the layer itself.</p> </blockquote> <p>So it is strange that why changing that will cause <code>self.view.layer</code> to act like a <code>CATransformLayer</code>.</p> <pre><code>-(void) viewDidAppear:(BOOL)animated { CATransform3D transform3D = CATransform3DIdentity; transform3D.m34 = -1.0 / 1000; transform3D = CATransform3DRotate(transform3D, M_PI / 4, 0, 1, 0); self.view.layer.sublayerTransform = transform3D; CALayer *layer1 = [[CALayer alloc] init]; layer1.zPosition = 33; layer1.frame = CGRectMake(100, 100, 100, 100); layer1.backgroundColor = [[UIColor orangeColor] CGColor]; [self.view.layer addSublayer:layer1]; CALayer *layer2 = [[CALayer alloc] init]; layer2.zPosition = 88; layer2.frame = CGRectMake(100, 120, 100, 100); layer2.backgroundColor = [[UIColor yellowColor] CGColor]; [self.view.layer addSublayer:layer2]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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