views:

977

answers:

1

I did this in awakeFromNib:

drawLayer = [CALayer layer];
self.layer = drawLayer;
[self setWantsLayer:YES];

there is a "add:" action

// some  business logic

    [drawLayer addSublayer:layer];
    [self layout];

-(void)layout
while(pg = [pageEnumr nextObject])

    {
    //rect is calculated so that layers are added in order (left to right)
    [pg setFrame:rect];
    }

I want the sublayers to be added from to top left side of the superLayer (CALayer of view) but they are added from bottom left

I tried affineTranform

   CGAffineTransform  trans = CGAffineTransformMake(1.0,0.0,0.0,-1.0,0.0,0.0);
   self.layer.affineTransform =    trans;

but scrolling make disappearing of my subLayers

I used transform

CATransform3D aTransform = CATransform3DIdentity;
aTransform = CATransform3DMakeRotation(M_PI, 1, 0, 0); 
self.layer..transform = aTransform;

I have to apply the transform to counter rotate the subLayers and after adding some 100 sublayers , scrolling becomes slow and application becomes unresponsive

if I don't apply any transform(no affine or no transform ) then application is fast even after addding 1000 sublayers

My application has to host huge number of layers of varying size. help me how to make the hosting layer take flipped co-ordinates ...

A: 

If you want to flip the coordinate space of your layer, I believe that inverting the Y scale is the better way to handle this. I did a similar thing in order to invert the coordinate system the other way on the iPhone (so that a CALayer hosted in a UIView would obey the Mac's Quartz coordinate system) using the following code:

self.layer.sublayerTransform = CATransform3DMakeScale(1.0f, -1.0f, 1.0f);

Try using this or the same transform applied to the layer's transform property. In my tests, this has not harmed performance any.

If you find that you need to apply a transform to counter the flipping for each of your layers, and that is killing performance, perhaps you should just manually calculate the correct Y coordinate for placement of each of the layers. It's not that hard to do (self.layer.frame.size.height - y - newLayer.frame.size.height, I believe).

Brad Larson
Don't forget to move the origin so that you're not simply going off into negative space. Translate y by the height of the layer, then scale as you showed.
Peter Hosey
With UIViews, I found that you don't need to translate in the Y when you apply the above sublayerTransform to the UIView's hosted layer. As I read it, the default anchor point for a layer is its center, and that is what the transform is applied about.
Brad Larson
You're right, though. Normally, you do need that Y translation.
Brad Larson
wow Brad , I see it works fine, but I am counter flipping each of the sublayers ,but performance is good so far , I am looking at optimizing it still.Once I find it I'l update the thread , thank you.