【问题标题】:How to rotate the text in a CATextLayer?如何旋转 CATextLayer 中的文本?
【发布时间】:2016-07-15 14:48:29
【问题描述】:

我在CATextLayer 中显示了一些文本,但它太大而无法放入定义的矩形中。我想让文本慢慢旋转,以便全部阅读。我不知道该怎么做。我希望有一种相对简单的方法可以做到这一点,如果没有,有人知道一个示例或教程的 URL,显示/教授如何做这样的事情。

    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:labelRect];
    [label setString:@"Some really long menu item that won't fit"];
    [label setAlignmentMode:kCAAlignmentLeft];
    [label setForegroundColor:whiteColor];

更新:我想我要描述的是文本本身会旋转。类似于 html marquee 标记之类的东西。

【问题讨论】:

  • 只需旋转 CATextLayer。使用属性@property CATransform3D transform;
  • @beryllium - 我不想转换标签,但希望标签内的文本缓慢旋转/动画,以便可以阅读所有文本。我对 transform 属性的理解是它会转换整个层本身,除非我误解了。
  • 我从您对@beryllium 的回复中猜测您的 CATextLayer 中有不想转换的子层?如果是这种情况,那么如果您还在 sublayerTransform 上应用了逆变换,他的建议就会奏效。

标签: objective-c catextlayer


【解决方案1】:

这对我有用,它会帮助你尝试这个....

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 2011-04-18
    • 2015-01-31
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多