views:

14

answers:

0

I have a layer that takes the whole iPhone screen. I want to change the coordinate system so that (-1,-1) is in the bottom left, and (1,1) in the top right; for the layer and its sub layers. how do I go about it?

This isn't as easy as setting the transform: previously I was overriding my view's drawRect, and accomplished the transformation thus:

-(void)RendertoContext:(CGContextRef) X
{
NSAssert(X != NULL, @"X null");

{
    // SCALE so that we range from TL(0, 0) - BR(2, -2)
    CGContextScaleCTM (X, 0.5 * bitmapSize.width, -0.5 * bitmapSize.height);

    // TRANSLATE so that we range from TL(-1, 1) - BR(1, -1)
    //   ie: a cartesian coordinate system, centred on (0, 0) with: 
    //       x increasing to the right
    //       y increasing upwards
    //       x&y each ranging from -1 to 1
    CGContextTranslateCTM(X, 1, -1);

    T = CGContextGetCTM (X);
}

CGRect wholeRect = CGRectMake(-1, -1, 2, 2);

but if I try to pull the same trick with a CALayer, like this:

-(void)createWheelLayer {
NSLog(@"createWheelLayer");


CGRect unitRect = CGRectMake(-1, 1, 2, 2);
self.wheelLayer = [[[CALayer alloc] init] autorelease];
[self.wheelLayer setGeometryFlipped: NO];
[self.wheelLayer setAnchorPoint: CGPointMake(0,0)];

CATransform3D T = CATransform3DIdentity;
T = CATransform3DScale(T, 16, 16, 1.0f);

[self.wheelLayer setTransform:T];

[self.wheelLayer setBounds: CGRectMake(0.0f, 0.0f, self.targetSize.width*1/16, 
                                                     self.targetSize.height*1/16)];

[self.wheelLayer setAnchorPoint:CGPointMake(0.5f, 0.5f)];
[self.wheelLayer setOpaque:NO];
[self.wheelLayer setShouldRasterize:NO];
[self.wheelLayer setDelegate:self];
[self.wheelLayer setNeedsDisplay];

}

the content I draw becomes very de-focused and blurred.

is there any solution to this problem? And could someone give me an explanation of what is going on?