CATextLayer rotate?

房东的猫 提交于 2019-12-06 08:54:48

问题


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?


回答1:


Try the following code:

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

instead of:

[textLayer setValue:[NSNumber numberWithDouble:M_PI / 2.f forKey:@"transform.rotation"];



回答2:


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".



来源:https://stackoverflow.com/questions/9269462/catextlayer-rotate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!