3

This should really work, but is not:

CATextLayer* textLayer = [CATextLayer layer];
textLayer.string = @"text";
[textLayer setValue:[NSNumber numberWithDouble:M_PI / 2.f forKey:@"transform.rotation"];
[self addSublayer:textLayer];

in fact, when i print the value at transform.rotation, it shows the correct answer. it just doesn't draw the textLayer rotated!

NSLog(@"rotation %@", [textLayer valueForKey:@"transform.rotation"]);

What am I doing wrong?

olynoise
  • 2,016
  • 2
  • 19
  • 32

2 Answers2

9

Try the following code:

textLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeRotation(M_PI_2));

instead of:

[textLayer setValue:[NSNumber numberWithDouble:M_PI / 2.f forKey:@"transform.rotation"];
sch
  • 27,436
  • 3
  • 68
  • 83
  • That did it! Though I still don't get why the other method didn't work. According to the documentation it really should. Thanks! – olynoise Feb 13 '12 at 23:41
0

The CALayer will remember any value you give it. I believe what you have it wrong because you need to rotate with "transform.rotation.z".

ZaBlanc
  • 4,679
  • 1
  • 35
  • 38
  • nope... the documentation says that "rotation" is the same as "rotation.z" i just tried this to make sure... but no luck. – olynoise Feb 13 '12 at 23:21