开发者

How to rotate the text in a CATextLayer?

I'm displaying some text in a CATextLayer but its to large to fit in the defined rect. I would like to have the text rotate slowly so it can all be read. I have no idea how to do that though. I'm hoping there is a relatively easy way to do this and if not that someone knows a url to an example or tutorial showing/teaching how to do such a thing.

    CATextLayer *label = [[CATextLayer alloc] init];
    NSRect labelRect;
    labelRect.origin.x = 20;
    labelRect.origin.y = -height / 3.5;
    labelRect.size.width = width - 40;
    labelRect.size.height = height;
    [label setFont:@"Helvetica-Bold"];
    [label setFontSize: fontSize];  
    [label setFrame:lab开发者_StackOverflow社区elRect];
    [label setString:@"Some really long menu item that won't fit"];
    [label setAlignmentMode:kCAAlignmentLeft];
    [label setForegroundColor:whiteColor];

update: I guess what I'm trying to describe would be that the text itself rotates. something like the html marquee tag would do.


This worked for me it will help you try this....

CGFloat radians = atan2f(_userResizableView2.transform.b, _userResizableView2.transform.a);

CGFloat flip=((UITextView*)_userResizableView2.contentView).transform.a;
NSLog(@"Flip x: %f Y : %f",((UITextView*)_userResizableView2.contentView).transform.a,((UITextView*)_userResizableView2.contentView).transform.b);
CGFloat degrees = radians * (180 / M_PI);
NSLog(@"Degree :%f",degrees);
float radiansToRotate = DEGREES_TO_RADIANS( -degrees );
CATransform3D zRotation;
zRotation = CATransform3DMakeRotation(radiansToRotate,0, 0, 1.0);
titleLayer.transform = CATransform3DScale(zRotation,flip, 1, 1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜